replace tabs with spaces
This commit is contained in:
parent
655de39c6b
commit
a796249867
53 changed files with 6195 additions and 6195 deletions
|
@ -1,25 +1,25 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\agents;
|
||||
|
||||
|
||||
/**
|
||||
* The BottomlevelAgent is the standard Agent and can have indefinite
|
||||
* SubAgents.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class BottomlevelAgent extends \nre\core\Agent
|
||||
{
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\agents;
|
||||
|
||||
|
||||
/**
|
||||
* The BottomlevelAgent is the standard Agent and can have indefinite
|
||||
* SubAgents.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class BottomlevelAgent extends \nre\core\Agent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\agents;
|
||||
|
||||
|
||||
/**
|
||||
* The IntermediateAgent assumes the task of a module. There is only one
|
||||
* IntermediateAgent per request.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class IntermediateAgent extends \nre\core\Agent
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the layout if it was explicitly defined.
|
||||
*
|
||||
* @param string $agentName Agent name
|
||||
* @return string Layout of the IntermediateAgent
|
||||
*/
|
||||
public static function getLayout($agentName)
|
||||
{
|
||||
// Determine classname
|
||||
$className = Autoloader::concatClassNames($agentName, 'Agent');
|
||||
|
||||
// Check property
|
||||
if(isset($className::$layout)) {
|
||||
return $className::$layout;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\agents;
|
||||
|
||||
|
||||
/**
|
||||
* The IntermediateAgent assumes the task of a module. There is only one
|
||||
* IntermediateAgent per request.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class IntermediateAgent extends \nre\core\Agent
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the layout if it was explicitly defined.
|
||||
*
|
||||
* @param string $agentName Agent name
|
||||
* @return string Layout of the IntermediateAgent
|
||||
*/
|
||||
public static function getLayout($agentName)
|
||||
{
|
||||
// Determine classname
|
||||
$className = Autoloader::concatClassNames($agentName, 'Agent');
|
||||
|
||||
// Check property
|
||||
if(isset($className::$layout)) {
|
||||
return $className::$layout;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,395 +1,395 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\agents;
|
||||
|
||||
|
||||
/**
|
||||
* The ToplevelAgent assumes the task of a FrontController. There is
|
||||
* only one per request.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ToplevelAgent extends \nre\core\Agent
|
||||
{
|
||||
/**
|
||||
* Stage: Load
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const STAGE_LOAD = 'load';
|
||||
/**
|
||||
* Stage: Run
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const STAGE_RUN = 'run';
|
||||
|
||||
/**
|
||||
* Current request
|
||||
*
|
||||
* @var \nre\core\Request
|
||||
*/
|
||||
private $request;
|
||||
/**
|
||||
* Current response
|
||||
*
|
||||
* @var \nre\core\Response
|
||||
*/
|
||||
private $response;
|
||||
/**
|
||||
* Layout instace
|
||||
*
|
||||
* @var \nre\core\Layout
|
||||
*/
|
||||
private $layout = null;
|
||||
/**
|
||||
* IntermediateAgent instance
|
||||
*
|
||||
* @var IntermediateAgent
|
||||
*/
|
||||
private $intermediateAgent = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a ToplevelAgent.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ControllerNotValidException
|
||||
* @throws \nre\exceptions\ControllerNotFoundException
|
||||
* @param \nre\core\Request $request Current request
|
||||
* @param \nre\core\Response $response Current response
|
||||
* @param \nre\core\Logger $log Log-system
|
||||
*/
|
||||
protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
|
||||
{
|
||||
// Store values
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
|
||||
|
||||
// Create response
|
||||
$response = clone $response;
|
||||
$response->clearParams(1);
|
||||
$response->addParams(
|
||||
null,
|
||||
\nre\configs\CoreConfig::$defaults['action']
|
||||
);
|
||||
|
||||
// Call parent constructor
|
||||
parent::__construct($request, $response, $log, true);
|
||||
|
||||
|
||||
// Load IntermediateAgent
|
||||
$this->loadIntermediateAgent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Run the Controller of this Agent and its SubAgents.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @param \nre\core\Request $request Current request
|
||||
* @param \nre\core\Response $response Current response
|
||||
* @return \Exception Last occurred exception of SubAgents
|
||||
*/
|
||||
public function run(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
try {
|
||||
return $this->_run($request, $response);
|
||||
}
|
||||
catch(\nre\exceptions\AccessDeniedException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_FORBIDDEN, self::STAGE_RUN);
|
||||
}
|
||||
catch(\nre\exceptions\ParamsNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN);
|
||||
}
|
||||
catch(\nre\exceptions\IdNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE, self::STAGE_RUN);
|
||||
}
|
||||
catch(\nre\exceptions\ActionNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate output of the Controller of this Agent and its
|
||||
* SubAgents.
|
||||
*
|
||||
* @param array $data View data
|
||||
* @return string Generated output
|
||||
*/
|
||||
public function render($data=array())
|
||||
{
|
||||
// Render IntermediateAgent
|
||||
$data = array();
|
||||
$data['intermediate'] = $this->intermediateAgent->render();
|
||||
|
||||
|
||||
// Render ToplevelAgent
|
||||
return parent::render($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the IntermediateAgent.
|
||||
*
|
||||
* @return \nre\agents\IntermediateAgent IntermediateAgent
|
||||
*/
|
||||
public function getIntermediateAgent()
|
||||
{
|
||||
return $this->intermediateAgent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load a SubAgent and add it.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @throws \nre\exceptions\FatalDatamodelException
|
||||
* @throws \nre\exceptions\AgentNotFoundException
|
||||
* @throws \nre\exceptions\AgentNotValidException
|
||||
* @param string $agentName Name of the Agent to load
|
||||
* @param mixed … Additional parameters for the agent
|
||||
*/
|
||||
protected function addSubAgent($agentName)
|
||||
{
|
||||
try {
|
||||
call_user_func_array(
|
||||
array(
|
||||
$this,
|
||||
'_addSubAgent'
|
||||
),
|
||||
func_get_args()
|
||||
);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
throw new \nre\exceptions\FatalDatamodelException($e->getDatamodelMessage(), $e->getDatamodelErrorNumber());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load IntermediateAgent defined by the current request.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
*/
|
||||
private function loadIntermediateAgent()
|
||||
{
|
||||
try {
|
||||
$this->_loadIntermediateAgent();
|
||||
}
|
||||
catch(\nre\exceptions\ViewNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load IntermediateAgent defined by the current request.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
*/
|
||||
private function _loadIntermediateAgent()
|
||||
{
|
||||
// Determine IntermediateAgent
|
||||
$agentName = $this->response->getParam(1);
|
||||
if(is_null($agentName)) {
|
||||
$agentName = $this->request->getParam(1, 'intermediate');
|
||||
$this->response->addParam($agentName);
|
||||
}
|
||||
|
||||
// Load IntermediateAgent
|
||||
IntermediateAgent::load($agentName);
|
||||
|
||||
|
||||
// Determine Action
|
||||
$action = $this->response->getParam(2);
|
||||
if(is_null($action)) {
|
||||
$action = $this->request->getParam(2, 'action');
|
||||
$this->response->addParam($action);
|
||||
}
|
||||
|
||||
// Construct IntermediateAgent
|
||||
$this->intermediateAgent = \nre\agents\IntermediateAgent::factory(
|
||||
$agentName,
|
||||
$this->request,
|
||||
$this->response,
|
||||
$this->log
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the Controller of this Agent and its SubAgents.
|
||||
*
|
||||
* @throws \nre\exceptions\AccessDeniedException
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param \nre\core\Request $request Current request
|
||||
* @param \nre\core\Response $response Current response
|
||||
* @return \Exception Last occurred exception of SubAgents
|
||||
*/
|
||||
private function _run(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
// Run IntermediateAgent
|
||||
$this->runIntermediateAgent();
|
||||
|
||||
|
||||
// TODO Request instead of response?
|
||||
$response = clone $response;
|
||||
$response->clearParams(2);
|
||||
$response->addParam(\nre\configs\CoreConfig::$defaults['action']);
|
||||
|
||||
|
||||
// Run ToplevelAgent
|
||||
return parent::run($request, $response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run IntermediateAgent.
|
||||
*
|
||||
* @throws \nre\exceptions\AccessDeniedException
|
||||
* @throws \nre\exceptions\ParamsNotValidException
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
*/
|
||||
private function runIntermediateAgent()
|
||||
{
|
||||
$this->intermediateAgent->run(
|
||||
$this->request,
|
||||
$this->response
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle an error that occurred during
|
||||
* loading/cnostructing/running of the IntermediateAgent.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @param \Exception $exception Occurred exception
|
||||
* @param int $httpStatusCode HTTP-statuscode
|
||||
* @param string $stage Stage of execution
|
||||
*/
|
||||
private function error($exception, $httpStatusCode, $stage=self::STAGE_LOAD)
|
||||
{
|
||||
// Log error
|
||||
$this->log($exception, \nre\core\Logger::LOGMODE_AUTO);
|
||||
|
||||
|
||||
try {
|
||||
// Define ErrorAgent
|
||||
$this->response->clearParams(1);
|
||||
$this->response->addParams(
|
||||
\nre\configs\AppConfig::$defaults['intermediate-error'],
|
||||
\nre\configs\CoreConfig::$defaults['action'],
|
||||
$httpStatusCode
|
||||
);
|
||||
|
||||
// Load ErrorAgent
|
||||
$this->_loadIntermediateAgent();
|
||||
|
||||
// Run ErrorAgent
|
||||
if($stage == self::STAGE_RUN) {
|
||||
$this->_run($this->request, $this->response);
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\ActionNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotValidException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotValidException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\ViewNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotValidException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotValidException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\agents;
|
||||
|
||||
|
||||
/**
|
||||
* The ToplevelAgent assumes the task of a FrontController. There is
|
||||
* only one per request.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ToplevelAgent extends \nre\core\Agent
|
||||
{
|
||||
/**
|
||||
* Stage: Load
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const STAGE_LOAD = 'load';
|
||||
/**
|
||||
* Stage: Run
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const STAGE_RUN = 'run';
|
||||
|
||||
/**
|
||||
* Current request
|
||||
*
|
||||
* @var \nre\core\Request
|
||||
*/
|
||||
private $request;
|
||||
/**
|
||||
* Current response
|
||||
*
|
||||
* @var \nre\core\Response
|
||||
*/
|
||||
private $response;
|
||||
/**
|
||||
* Layout instace
|
||||
*
|
||||
* @var \nre\core\Layout
|
||||
*/
|
||||
private $layout = null;
|
||||
/**
|
||||
* IntermediateAgent instance
|
||||
*
|
||||
* @var IntermediateAgent
|
||||
*/
|
||||
private $intermediateAgent = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a ToplevelAgent.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ControllerNotValidException
|
||||
* @throws \nre\exceptions\ControllerNotFoundException
|
||||
* @param \nre\core\Request $request Current request
|
||||
* @param \nre\core\Response $response Current response
|
||||
* @param \nre\core\Logger $log Log-system
|
||||
*/
|
||||
protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
|
||||
{
|
||||
// Store values
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
|
||||
|
||||
// Create response
|
||||
$response = clone $response;
|
||||
$response->clearParams(1);
|
||||
$response->addParams(
|
||||
null,
|
||||
\nre\configs\CoreConfig::$defaults['action']
|
||||
);
|
||||
|
||||
// Call parent constructor
|
||||
parent::__construct($request, $response, $log, true);
|
||||
|
||||
|
||||
// Load IntermediateAgent
|
||||
$this->loadIntermediateAgent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Run the Controller of this Agent and its SubAgents.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @param \nre\core\Request $request Current request
|
||||
* @param \nre\core\Response $response Current response
|
||||
* @return \Exception Last occurred exception of SubAgents
|
||||
*/
|
||||
public function run(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
try {
|
||||
return $this->_run($request, $response);
|
||||
}
|
||||
catch(\nre\exceptions\AccessDeniedException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_FORBIDDEN, self::STAGE_RUN);
|
||||
}
|
||||
catch(\nre\exceptions\ParamsNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN);
|
||||
}
|
||||
catch(\nre\exceptions\IdNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE, self::STAGE_RUN);
|
||||
}
|
||||
catch(\nre\exceptions\ActionNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate output of the Controller of this Agent and its
|
||||
* SubAgents.
|
||||
*
|
||||
* @param array $data View data
|
||||
* @return string Generated output
|
||||
*/
|
||||
public function render($data=array())
|
||||
{
|
||||
// Render IntermediateAgent
|
||||
$data = array();
|
||||
$data['intermediate'] = $this->intermediateAgent->render();
|
||||
|
||||
|
||||
// Render ToplevelAgent
|
||||
return parent::render($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the IntermediateAgent.
|
||||
*
|
||||
* @return \nre\agents\IntermediateAgent IntermediateAgent
|
||||
*/
|
||||
public function getIntermediateAgent()
|
||||
{
|
||||
return $this->intermediateAgent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load a SubAgent and add it.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @throws \nre\exceptions\FatalDatamodelException
|
||||
* @throws \nre\exceptions\AgentNotFoundException
|
||||
* @throws \nre\exceptions\AgentNotValidException
|
||||
* @param string $agentName Name of the Agent to load
|
||||
* @param mixed … Additional parameters for the agent
|
||||
*/
|
||||
protected function addSubAgent($agentName)
|
||||
{
|
||||
try {
|
||||
call_user_func_array(
|
||||
array(
|
||||
$this,
|
||||
'_addSubAgent'
|
||||
),
|
||||
func_get_args()
|
||||
);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
throw new \nre\exceptions\FatalDatamodelException($e->getDatamodelMessage(), $e->getDatamodelErrorNumber());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load IntermediateAgent defined by the current request.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
*/
|
||||
private function loadIntermediateAgent()
|
||||
{
|
||||
try {
|
||||
$this->_loadIntermediateAgent();
|
||||
}
|
||||
catch(\nre\exceptions\ViewNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load IntermediateAgent defined by the current request.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
*/
|
||||
private function _loadIntermediateAgent()
|
||||
{
|
||||
// Determine IntermediateAgent
|
||||
$agentName = $this->response->getParam(1);
|
||||
if(is_null($agentName)) {
|
||||
$agentName = $this->request->getParam(1, 'intermediate');
|
||||
$this->response->addParam($agentName);
|
||||
}
|
||||
|
||||
// Load IntermediateAgent
|
||||
IntermediateAgent::load($agentName);
|
||||
|
||||
|
||||
// Determine Action
|
||||
$action = $this->response->getParam(2);
|
||||
if(is_null($action)) {
|
||||
$action = $this->request->getParam(2, 'action');
|
||||
$this->response->addParam($action);
|
||||
}
|
||||
|
||||
// Construct IntermediateAgent
|
||||
$this->intermediateAgent = \nre\agents\IntermediateAgent::factory(
|
||||
$agentName,
|
||||
$this->request,
|
||||
$this->response,
|
||||
$this->log
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the Controller of this Agent and its SubAgents.
|
||||
*
|
||||
* @throws \nre\exceptions\AccessDeniedException
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param \nre\core\Request $request Current request
|
||||
* @param \nre\core\Response $response Current response
|
||||
* @return \Exception Last occurred exception of SubAgents
|
||||
*/
|
||||
private function _run(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
// Run IntermediateAgent
|
||||
$this->runIntermediateAgent();
|
||||
|
||||
|
||||
// TODO Request instead of response?
|
||||
$response = clone $response;
|
||||
$response->clearParams(2);
|
||||
$response->addParam(\nre\configs\CoreConfig::$defaults['action']);
|
||||
|
||||
|
||||
// Run ToplevelAgent
|
||||
return parent::run($request, $response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run IntermediateAgent.
|
||||
*
|
||||
* @throws \nre\exceptions\AccessDeniedException
|
||||
* @throws \nre\exceptions\ParamsNotValidException
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
*/
|
||||
private function runIntermediateAgent()
|
||||
{
|
||||
$this->intermediateAgent->run(
|
||||
$this->request,
|
||||
$this->response
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle an error that occurred during
|
||||
* loading/cnostructing/running of the IntermediateAgent.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @param \Exception $exception Occurred exception
|
||||
* @param int $httpStatusCode HTTP-statuscode
|
||||
* @param string $stage Stage of execution
|
||||
*/
|
||||
private function error($exception, $httpStatusCode, $stage=self::STAGE_LOAD)
|
||||
{
|
||||
// Log error
|
||||
$this->log($exception, \nre\core\Logger::LOGMODE_AUTO);
|
||||
|
||||
|
||||
try {
|
||||
// Define ErrorAgent
|
||||
$this->response->clearParams(1);
|
||||
$this->response->addParams(
|
||||
\nre\configs\AppConfig::$defaults['intermediate-error'],
|
||||
\nre\configs\CoreConfig::$defaults['action'],
|
||||
$httpStatusCode
|
||||
);
|
||||
|
||||
// Load ErrorAgent
|
||||
$this->_loadIntermediateAgent();
|
||||
|
||||
// Run ErrorAgent
|
||||
if($stage == self::STAGE_RUN) {
|
||||
$this->_run($this->request, $this->response);
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\ActionNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotValidException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotValidException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\ViewNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotValidException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotValidException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotFoundException $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
throw new \nre\exceptions\ServiceUnavailableException($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
486
apis/WebApi.inc
486
apis/WebApi.inc
|
@ -1,250 +1,250 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\apis;
|
||||
|
||||
|
||||
/**
|
||||
* WebApi-implementation.
|
||||
*
|
||||
* This class runs and renders an web-applictaion.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class WebApi extends \nre\core\Api
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new WebApi.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
new \nre\requests\WebRequest(),
|
||||
new \nre\responses\WebResponse()
|
||||
);
|
||||
|
||||
// Add routes
|
||||
$this->addRoutes();
|
||||
|
||||
// Disable screen logging for AJAX requests
|
||||
if($this->request->getParam(0, 'toplevel') == 'ajax') {
|
||||
$this->log->disableAutoLogToScreen();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Run application.
|
||||
*
|
||||
* This method runs the application and handles all errors.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
try {
|
||||
$exception = parent::run();
|
||||
|
||||
if(!is_null($exception)) {
|
||||
$this->errorService($exception);
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\ServiceUnavailableException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ActionNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\FatalDatamodelException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ViewNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNoaatValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render output.
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
// Generate output
|
||||
parent::render();
|
||||
|
||||
|
||||
// Set HTTP-header
|
||||
$this->response->header();
|
||||
|
||||
// Show output
|
||||
echo $this->response->getOutput();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add routes (normal and reverse) defined in the AppConfig.
|
||||
*/
|
||||
private function addRoutes()
|
||||
{
|
||||
// Normal routes
|
||||
if(property_exists('\nre\configs\AppConfig', 'routes')) {
|
||||
foreach(\nre\configs\AppConfig::$routes as &$route) {
|
||||
$this->request->addRoute($route[0], $route[1], $route[2]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
// Reverse routes
|
||||
if(property_exists('\nre\configs\AppConfig', 'reverseRoutes')) {
|
||||
foreach(\nre\configs\AppConfig::$reverseRoutes as &$route) {
|
||||
$this->request->addReverseRoute($route[0], $route[1], $route[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// Revalidate request
|
||||
$this->request->revalidate();
|
||||
}
|
||||
namespace nre\apis;
|
||||
|
||||
|
||||
/**
|
||||
* Handle an error that orrcurred during the
|
||||
* loading/constructing/running of the ToplevelAgent.
|
||||
*
|
||||
* @param \Exception $exception Occurred exception
|
||||
* @param int $httpStatusCode HTTP-statuscode
|
||||
*/
|
||||
private function error(\nre\core\Exception $exception, $httpStatusCode)
|
||||
{
|
||||
// Log error message
|
||||
$this->log($exception, \nre\core\Logger::LOGMODE_AUTO);
|
||||
|
||||
try {
|
||||
// Set agent for handling errors
|
||||
$this->response->clearParams();
|
||||
$this->response->addParams(
|
||||
\nre\configs\AppConfig::$defaults['toplevel-error'],
|
||||
\nre\configs\AppConfig::$defaults['intermediate-error'],
|
||||
\nre\configs\CoreConfig::$defaults['action'],
|
||||
$httpStatusCode
|
||||
);
|
||||
|
||||
// Run this agent
|
||||
parent::run();
|
||||
}
|
||||
catch(\nre\exceptions\ServiceUnavailableException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ActionNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotValidException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotValidException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ViewNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotValidException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotValidException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle a error which cannot be handles by the system (and
|
||||
* HTTP 503).
|
||||
*
|
||||
* @param \Exception $exception Occurred exception
|
||||
*/
|
||||
private function errorService($exception)
|
||||
{
|
||||
// Log error message
|
||||
$this->log($exception, \nre\core\Logger::LOGMODE_AUTO);
|
||||
|
||||
// Set HTTP-rtatuscode
|
||||
$this->response->addHeader(\nre\core\WebUtils::getHttpHeader(503));
|
||||
|
||||
|
||||
// Read and print static error file
|
||||
$fileName = ROOT.DS.\nre\configs\CoreConfig::getClassDir('views').DS.\nre\configs\CoreConfig::$defaults['errorFile'].\nre\configs\CoreConfig::getFileExt('views');
|
||||
ob_start();
|
||||
include($fileName);
|
||||
$this->response->setOutput(ob_get_clean());
|
||||
|
||||
|
||||
// Prevent further execution
|
||||
$this->response->setExit();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* WebApi-implementation.
|
||||
*
|
||||
* This class runs and renders an web-applictaion.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class WebApi extends \nre\core\Api
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new WebApi.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
new \nre\requests\WebRequest(),
|
||||
new \nre\responses\WebResponse()
|
||||
);
|
||||
|
||||
// Add routes
|
||||
$this->addRoutes();
|
||||
|
||||
// Disable screen logging for AJAX requests
|
||||
if($this->request->getParam(0, 'toplevel') == 'ajax') {
|
||||
$this->log->disableAutoLogToScreen();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Run application.
|
||||
*
|
||||
* This method runs the application and handles all errors.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
try {
|
||||
$exception = parent::run();
|
||||
|
||||
if(!is_null($exception)) {
|
||||
$this->errorService($exception);
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\ServiceUnavailableException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ActionNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\FatalDatamodelException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ViewNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNoaatValidException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotFoundException $e) {
|
||||
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render output.
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
// Generate output
|
||||
parent::render();
|
||||
|
||||
|
||||
// Set HTTP-header
|
||||
$this->response->header();
|
||||
|
||||
// Show output
|
||||
echo $this->response->getOutput();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add routes (normal and reverse) defined in the AppConfig.
|
||||
*/
|
||||
private function addRoutes()
|
||||
{
|
||||
// Normal routes
|
||||
if(property_exists('\nre\configs\AppConfig', 'routes')) {
|
||||
foreach(\nre\configs\AppConfig::$routes as &$route) {
|
||||
$this->request->addRoute($route[0], $route[1], $route[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// Reverse routes
|
||||
if(property_exists('\nre\configs\AppConfig', 'reverseRoutes')) {
|
||||
foreach(\nre\configs\AppConfig::$reverseRoutes as &$route) {
|
||||
$this->request->addReverseRoute($route[0], $route[1], $route[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// Revalidate request
|
||||
$this->request->revalidate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle an error that orrcurred during the
|
||||
* loading/constructing/running of the ToplevelAgent.
|
||||
*
|
||||
* @param \Exception $exception Occurred exception
|
||||
* @param int $httpStatusCode HTTP-statuscode
|
||||
*/
|
||||
private function error(\nre\core\Exception $exception, $httpStatusCode)
|
||||
{
|
||||
// Log error message
|
||||
$this->log($exception, \nre\core\Logger::LOGMODE_AUTO);
|
||||
|
||||
try {
|
||||
// Set agent for handling errors
|
||||
$this->response->clearParams();
|
||||
$this->response->addParams(
|
||||
\nre\configs\AppConfig::$defaults['toplevel-error'],
|
||||
\nre\configs\AppConfig::$defaults['intermediate-error'],
|
||||
\nre\configs\CoreConfig::$defaults['action'],
|
||||
$httpStatusCode
|
||||
);
|
||||
|
||||
// Run this agent
|
||||
parent::run();
|
||||
}
|
||||
catch(\nre\exceptions\ServiceUnavailableException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ActionNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotValidException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\DriverNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotValidException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ViewNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotValidException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\ControllerNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotValidException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(\nre\exceptions\AgentNotFoundException $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
$this->errorService($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle a error which cannot be handles by the system (and
|
||||
* HTTP 503).
|
||||
*
|
||||
* @param \Exception $exception Occurred exception
|
||||
*/
|
||||
private function errorService($exception)
|
||||
{
|
||||
// Log error message
|
||||
$this->log($exception, \nre\core\Logger::LOGMODE_AUTO);
|
||||
|
||||
// Set HTTP-rtatuscode
|
||||
$this->response->addHeader(\nre\core\WebUtils::getHttpHeader(503));
|
||||
|
||||
|
||||
// Read and print static error file
|
||||
$fileName = ROOT.DS.\nre\configs\CoreConfig::getClassDir('views').DS.\nre\configs\CoreConfig::$defaults['errorFile'].\nre\configs\CoreConfig::getFileExt('views');
|
||||
ob_start();
|
||||
include($fileName);
|
||||
$this->response->setOutput(ob_get_clean());
|
||||
|
||||
|
||||
// Prevent further execution
|
||||
$this->response->setExit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
// Include required classes
|
||||
require_once(ROOT.DS.'configs'.DS.'CoreConfig.inc');
|
||||
require_once(ROOT.DS.\nre\configs\CoreConfig::getClassDir('core').DS.'Autoloader.inc');
|
||||
|
||||
|
||||
// Set PHP-logging
|
||||
ini_set('error_log', ROOT.DS.\nre\configs\CoreConfig::getClassDir('logs').DS.'php'.\nre\configs\CoreConfig::getFileExt('logs'));
|
||||
|
||||
// Register autoloader
|
||||
\nre\core\Autoloader::register();
|
||||
|
||||
|
||||
// Initialize WebApi
|
||||
$webApi = new \nre\apis\WebApi();
|
||||
|
||||
// Run WebApi
|
||||
$webApi->run();
|
||||
|
||||
// Render output
|
||||
$webApi->render();
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
// Include required classes
|
||||
require_once(ROOT.DS.'configs'.DS.'CoreConfig.inc');
|
||||
require_once(ROOT.DS.\nre\configs\CoreConfig::getClassDir('core').DS.'Autoloader.inc');
|
||||
|
||||
|
||||
// Set PHP-logging
|
||||
ini_set('error_log', ROOT.DS.\nre\configs\CoreConfig::getClassDir('logs').DS.'php'.\nre\configs\CoreConfig::getFileExt('logs'));
|
||||
|
||||
// Register autoloader
|
||||
\nre\core\Autoloader::register();
|
||||
|
||||
|
||||
// Initialize WebApi
|
||||
$webApi = new \nre\apis\WebApi();
|
||||
|
||||
// Run WebApi
|
||||
$webApi->run();
|
||||
|
||||
// Render output
|
||||
$webApi->render();
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,75 +1,75 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\configs;
|
||||
|
||||
|
||||
/**
|
||||
* Application configuration.
|
||||
*
|
||||
* This class contains static variables with configuration values for
|
||||
* the specific application.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
final class AppConfig
|
||||
{
|
||||
|
||||
/**
|
||||
* Application values
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $app = array(
|
||||
//'namespace' => '',
|
||||
//'timeZone' => ''
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Default values
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $defaults = array(
|
||||
//'toplevel' => '',
|
||||
//'toplevel-error' => '',
|
||||
//'intermediate' => '',
|
||||
//'intermediate-error' => ''
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Routes
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $routes = array(
|
||||
//array('<pattern>', '<replace>', '<is_last>')
|
||||
);
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\configs;
|
||||
|
||||
|
||||
/**
|
||||
* Reverse routes
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $reverseRoutes = array(
|
||||
//array('<pattern>', '<replace>', '<is_last>')
|
||||
);
|
||||
|
||||
}
|
||||
/**
|
||||
* Application configuration.
|
||||
*
|
||||
* This class contains static variables with configuration values for
|
||||
* the specific application.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
final class AppConfig
|
||||
{
|
||||
|
||||
/**
|
||||
* Application values
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $app = array(
|
||||
//'namespace' => '',
|
||||
//'timeZone' => ''
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Default values
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $defaults = array(
|
||||
//'toplevel' => '',
|
||||
//'toplevel-error' => '',
|
||||
//'intermediate' => '',
|
||||
//'intermediate-error' => ''
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Routes
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $routes = array(
|
||||
//array('<pattern>', '<replace>', '<is_last>')
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Reverse routes
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $reverseRoutes = array(
|
||||
//array('<pattern>', '<replace>', '<is_last>')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,167 +1,167 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\configs;
|
||||
|
||||
|
||||
/**
|
||||
* Core configuration.
|
||||
*
|
||||
* This class contains static variables with configuration values.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
final class CoreConfig
|
||||
{
|
||||
|
||||
/**
|
||||
* Core values
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $core = array(
|
||||
'namespace' => 'nre\\',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Directories
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $dirs = array(
|
||||
'core' => 'core',
|
||||
'publicDir' => 'www'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* File extensions
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $fileExts = array(
|
||||
'default' => 'inc',
|
||||
'views' => 'tpl',
|
||||
'logs' => 'log',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Default values
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $defaults = array(
|
||||
'action' => 'index',
|
||||
'errorFile' => 'error',
|
||||
'inlineErrorFile' => 'inlineerror'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Miscellaneous settings
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $misc = array(
|
||||
'fileExtDot' => '.'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Logging settings
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $log = array(
|
||||
'filename' => 'errors',
|
||||
'format' => 'Fehler %d: %s in %s, Zeile %d'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Class-specific settings
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $classes = array(
|
||||
'linker' => array(
|
||||
'url' => array(
|
||||
'length' => 128,
|
||||
'delimiter' => '-'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Determine the directory for a specific classtype.
|
||||
*
|
||||
* @param string $classType Classtype to get directory of
|
||||
* @return string Directory of given classtype
|
||||
*/
|
||||
public static function getClassDir($classType)
|
||||
{
|
||||
// Default directory (for core classes)
|
||||
$classDir = self::$dirs['core'];
|
||||
|
||||
// Configurable directory
|
||||
if(array_key_exists($classType, self::$dirs)) {
|
||||
$classDir = self::$dirs[$classType];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default directory for classtype
|
||||
if(is_dir(ROOT.DS.$classType)) {
|
||||
$classDir = $classType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return directory
|
||||
return $classDir;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the file extension for a specific filetype.
|
||||
*
|
||||
* @param string $fileType Filetype to get file extension of
|
||||
* @return string File extension of given filetype
|
||||
*/
|
||||
public static function getFileExt($fileType)
|
||||
{
|
||||
// Default file extension
|
||||
$fileExt = self::$fileExts['default'];
|
||||
|
||||
// Configurable file extension
|
||||
if(array_key_exists($fileType, self::$fileExts)) {
|
||||
$fileExt = self::$fileExts[$fileType];
|
||||
}
|
||||
|
||||
|
||||
// Return file extension
|
||||
return self::$misc['fileExtDot'].$fileExt;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\configs;
|
||||
|
||||
|
||||
/**
|
||||
* Core configuration.
|
||||
*
|
||||
* This class contains static variables with configuration values.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
final class CoreConfig
|
||||
{
|
||||
|
||||
/**
|
||||
* Core values
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $core = array(
|
||||
'namespace' => 'nre\\',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Directories
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $dirs = array(
|
||||
'core' => 'core',
|
||||
'publicDir' => 'www'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* File extensions
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $fileExts = array(
|
||||
'default' => 'inc',
|
||||
'views' => 'tpl',
|
||||
'logs' => 'log',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Default values
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $defaults = array(
|
||||
'action' => 'index',
|
||||
'errorFile' => 'error',
|
||||
'inlineErrorFile' => 'inlineerror'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Miscellaneous settings
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $misc = array(
|
||||
'fileExtDot' => '.'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Logging settings
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $log = array(
|
||||
'filename' => 'errors',
|
||||
'format' => 'Fehler %d: %s in %s, Zeile %d'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Class-specific settings
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
public static $classes = array(
|
||||
'linker' => array(
|
||||
'url' => array(
|
||||
'length' => 128,
|
||||
'delimiter' => '-'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Determine the directory for a specific classtype.
|
||||
*
|
||||
* @param string $classType Classtype to get directory of
|
||||
* @return string Directory of given classtype
|
||||
*/
|
||||
public static function getClassDir($classType)
|
||||
{
|
||||
// Default directory (for core classes)
|
||||
$classDir = self::$dirs['core'];
|
||||
|
||||
// Configurable directory
|
||||
if(array_key_exists($classType, self::$dirs)) {
|
||||
$classDir = self::$dirs[$classType];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default directory for classtype
|
||||
if(is_dir(ROOT.DS.$classType)) {
|
||||
$classDir = $classType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return directory
|
||||
return $classDir;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the file extension for a specific filetype.
|
||||
*
|
||||
* @param string $fileType Filetype to get file extension of
|
||||
* @return string File extension of given filetype
|
||||
*/
|
||||
public static function getFileExt($fileType)
|
||||
{
|
||||
// Default file extension
|
||||
$fileExt = self::$fileExts['default'];
|
||||
|
||||
// Configurable file extension
|
||||
if(array_key_exists($fileType, self::$fileExts)) {
|
||||
$fileExt = self::$fileExts[$fileType];
|
||||
}
|
||||
|
||||
|
||||
// Return file extension
|
||||
return self::$misc['fileExtDot'].$fileExt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
1208
core/Agent.inc
1208
core/Agent.inc
File diff suppressed because it is too large
Load diff
318
core/Api.inc
318
core/Api.inc
|
@ -1,163 +1,163 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class to implement an API.
|
||||
*
|
||||
* The API is the center of each application and specifies how and what
|
||||
* to run and render.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class Api
|
||||
{
|
||||
/**
|
||||
* Die aktuelle Anfrage
|
||||
*
|
||||
* @var Request
|
||||
*/
|
||||
protected $request;
|
||||
/**
|
||||
* Der Toplevelagent
|
||||
*
|
||||
* @var \nre\agents\ToplevelAgent
|
||||
*/
|
||||
private $toplevelAgent = null;
|
||||
/**
|
||||
* Die aktuelle Antwort
|
||||
*
|
||||
* @var Response
|
||||
*/
|
||||
protected $response;
|
||||
/**
|
||||
* Log-System
|
||||
*
|
||||
* @var Logger
|
||||
*/
|
||||
protected $log;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new API.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function __construct(Request $request, Response $response)
|
||||
{
|
||||
// Store request
|
||||
$this->request = $request;
|
||||
|
||||
// Store response
|
||||
$this->response = $response;
|
||||
|
||||
// Init logging
|
||||
$this->log = new \nre\core\Logger();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Run the application.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ControllerNotValidException
|
||||
* @throws \nre\exceptions\ControllerNotFoundException
|
||||
* @throws \nre\exceptions\AgentNotValidException
|
||||
* @throws \nre\exceptions\AgentNotFoundException
|
||||
* @return \Exception Last occurred exception of an subagent
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Load ToplevelAgent
|
||||
$this->loadToplevelAgent();
|
||||
|
||||
// Run ToplevelAgent
|
||||
return $this->toplevelAgent->run($this->request, $this->response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the output.
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
// Check exit-status
|
||||
if($this->response->getExit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Render ToplevelAgent
|
||||
$this->response->setOutput($this->toplevelAgent->render());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Log an exception
|
||||
*
|
||||
* @param \Exception $exception Occurred exception
|
||||
* @param int $logMode Log-mode
|
||||
*/
|
||||
protected function log($exception, $logMode)
|
||||
{
|
||||
$this->log->log(
|
||||
$exception->getMessage(),
|
||||
$logMode
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the ToplevelAgent specified by the request.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @throws \nre\exceptions\AgentNotValidException
|
||||
* @throws \nre\exceptions\AgentNotFoundException
|
||||
*/
|
||||
private function loadToplevelAgent()
|
||||
{
|
||||
// Determine agent
|
||||
$agentName = $this->response->getParam(0);
|
||||
if(is_null($agentName)) {
|
||||
$agentName = $this->request->getParam(0, 'toplevel');
|
||||
$this->response->addParam($agentName);
|
||||
}
|
||||
|
||||
// Load agent
|
||||
\nre\agents\ToplevelAgent::load($agentName);
|
||||
|
||||
// Construct agent
|
||||
$this->toplevelAgent = \nre\agents\ToplevelAgent::factory(
|
||||
$agentName,
|
||||
$this->request,
|
||||
$this->response,
|
||||
$this->log
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class to implement an API.
|
||||
*
|
||||
* The API is the center of each application and specifies how and what
|
||||
* to run and render.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class Api
|
||||
{
|
||||
/**
|
||||
* Die aktuelle Anfrage
|
||||
*
|
||||
* @var Request
|
||||
*/
|
||||
protected $request;
|
||||
/**
|
||||
* Der Toplevelagent
|
||||
*
|
||||
* @var \nre\agents\ToplevelAgent
|
||||
*/
|
||||
private $toplevelAgent = null;
|
||||
/**
|
||||
* Die aktuelle Antwort
|
||||
*
|
||||
* @var Response
|
||||
*/
|
||||
protected $response;
|
||||
/**
|
||||
* Log-System
|
||||
*
|
||||
* @var Logger
|
||||
*/
|
||||
protected $log;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new API.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function __construct(Request $request, Response $response)
|
||||
{
|
||||
// Store request
|
||||
$this->request = $request;
|
||||
|
||||
// Store response
|
||||
$this->response = $response;
|
||||
|
||||
// Init logging
|
||||
$this->log = new \nre\core\Logger();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Run the application.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ControllerNotValidException
|
||||
* @throws \nre\exceptions\ControllerNotFoundException
|
||||
* @throws \nre\exceptions\AgentNotValidException
|
||||
* @throws \nre\exceptions\AgentNotFoundException
|
||||
* @return \Exception Last occurred exception of an subagent
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Load ToplevelAgent
|
||||
$this->loadToplevelAgent();
|
||||
|
||||
// Run ToplevelAgent
|
||||
return $this->toplevelAgent->run($this->request, $this->response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the output.
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
// Check exit-status
|
||||
if($this->response->getExit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Render ToplevelAgent
|
||||
$this->response->setOutput($this->toplevelAgent->render());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Log an exception
|
||||
*
|
||||
* @param \Exception $exception Occurred exception
|
||||
* @param int $logMode Log-mode
|
||||
*/
|
||||
protected function log($exception, $logMode)
|
||||
{
|
||||
$this->log->log(
|
||||
$exception->getMessage(),
|
||||
$logMode
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the ToplevelAgent specified by the request.
|
||||
*
|
||||
* @throws \nre\exceptions\ServiceUnavailableException
|
||||
* @throws \nre\exceptions\AgentNotValidException
|
||||
* @throws \nre\exceptions\AgentNotFoundException
|
||||
*/
|
||||
private function loadToplevelAgent()
|
||||
{
|
||||
// Determine agent
|
||||
$agentName = $this->response->getParam(0);
|
||||
if(is_null($agentName)) {
|
||||
$agentName = $this->request->getParam(0, 'toplevel');
|
||||
$this->response->addParam($agentName);
|
||||
}
|
||||
|
||||
// Load agent
|
||||
\nre\agents\ToplevelAgent::load($agentName);
|
||||
|
||||
// Construct agent
|
||||
$this->toplevelAgent = \nre\agents\ToplevelAgent::factory(
|
||||
$agentName,
|
||||
$this->request,
|
||||
$this->response,
|
||||
$this->log
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,98 +1,98 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Autoloader.
|
||||
*
|
||||
* This class tries to load not yet used classes.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Autoloader
|
||||
{
|
||||
/**
|
||||
* Private construct().
|
||||
*/
|
||||
private function __construct() {}
|
||||
|
||||
/**
|
||||
* Private clone().
|
||||
*/
|
||||
private function __clone() {}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Register load-method.
|
||||
*/
|
||||
public static function register()
|
||||
{
|
||||
spl_autoload_register(
|
||||
array(
|
||||
get_class(),
|
||||
'load'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Look for the given class and try to load it.
|
||||
*
|
||||
* @param string $fullClassName Die zu ladende Klasse
|
||||
*/
|
||||
public static function load($fullClassName)
|
||||
{
|
||||
$fullClassNameA = explode('\\', $fullClassName);
|
||||
|
||||
if(strpos($fullClassName, \nre\configs\CoreConfig::$core['namespace']) !== 0)
|
||||
{
|
||||
// App
|
||||
$className = array_slice($fullClassNameA, substr_count(\nre\configs\AppConfig::$app['namespace'], '\\'));
|
||||
array_unshift($className, \nre\configs\CoreConfig::getClassDir('app'));
|
||||
$filename = ROOT.DS.implode(DS, $className).\nre\configs\CoreConfig::getFileExt('includes');
|
||||
if(file_exists($filename)) {
|
||||
require_once($filename);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Core
|
||||
$className = array_slice($fullClassNameA, substr_count(\nre\configs\CoreConfig::$core['namespace'], '\\'));
|
||||
$filename = ROOT.DS.implode(DS, $className).\nre\configs\CoreConfig::getFileExt('includes');
|
||||
if(file_exists($filename)) {
|
||||
require_once($filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine classtype of a class.
|
||||
*
|
||||
* @param string $className Name of the class to determine the classtype of
|
||||
* @return string Classtype of the given class
|
||||
*/
|
||||
public static function getClassType($className)
|
||||
{
|
||||
// CamelCase
|
||||
return strtolower(preg_replace('/^.*([A-Z][^A-Z]+)$/', '$1', $className));
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Autoloader.
|
||||
*
|
||||
* This class tries to load not yet used classes.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Autoloader
|
||||
{
|
||||
/**
|
||||
* Private construct().
|
||||
*/
|
||||
private function __construct() {}
|
||||
|
||||
/**
|
||||
* Private clone().
|
||||
*/
|
||||
private function __clone() {}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Register load-method.
|
||||
*/
|
||||
public static function register()
|
||||
{
|
||||
spl_autoload_register(
|
||||
array(
|
||||
get_class(),
|
||||
'load'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Look for the given class and try to load it.
|
||||
*
|
||||
* @param string $fullClassName Name of class to load
|
||||
*/
|
||||
public static function load($fullClassName)
|
||||
{
|
||||
$fullClassNameA = explode('\\', $fullClassName);
|
||||
|
||||
if(strpos($fullClassName, \nre\configs\CoreConfig::$core['namespace']) !== 0)
|
||||
{
|
||||
// App
|
||||
$className = array_slice($fullClassNameA, substr_count(\nre\configs\AppConfig::$app['namespace'], '\\'));
|
||||
array_unshift($className, \nre\configs\CoreConfig::getClassDir('app'));
|
||||
$filename = ROOT.DS.implode(DS, $className).\nre\configs\CoreConfig::getFileExt('includes');
|
||||
if(file_exists($filename)) {
|
||||
require_once($filename);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Core
|
||||
$className = array_slice($fullClassNameA, substr_count(\nre\configs\CoreConfig::$core['namespace'], '\\'));
|
||||
$filename = ROOT.DS.implode(DS, $className).\nre\configs\CoreConfig::getFileExt('includes');
|
||||
if(file_exists($filename)) {
|
||||
require_once($filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine classtype of a class.
|
||||
*
|
||||
* @param string $className Name of the class to determine the classtype of
|
||||
* @return string Classtype of the given class
|
||||
*/
|
||||
public static function getClassType($className)
|
||||
{
|
||||
// CamelCase
|
||||
return strtolower(preg_replace('/^.*([A-Z][^A-Z]+)$/', '$1', $className));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,129 +1,129 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Class for safely loading classes.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load a class.
|
||||
*
|
||||
* @throws \nre\exceptions\ClassNotFoundException
|
||||
* @param string $className Name of the class to load
|
||||
*/
|
||||
public static function load($fullClassName)
|
||||
{
|
||||
// Determine folder to look in
|
||||
$className = explode('\\', $fullClassName);
|
||||
$className = array_slice($className, substr_count(\nre\configs\AppConfig::$app['namespace'], '\\'));
|
||||
|
||||
// Determine filename
|
||||
$fileName = ROOT.DS.implode(DS, $className). \nre\configs\CoreConfig::getFileExt('includes');
|
||||
|
||||
|
||||
// Check file
|
||||
if(!file_exists($fileName))
|
||||
{
|
||||
throw new \nre\exceptions\ClassNotFoundException(
|
||||
$fullClassName
|
||||
);
|
||||
}
|
||||
|
||||
// Include file
|
||||
include_once($fileName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check inheritance of a class.
|
||||
*
|
||||
* @throws \nre\exceptions\ClassNotValidException
|
||||
* @param string $className Name of the class to check
|
||||
* @param string $parentClassName Name of the parent class
|
||||
*/
|
||||
public static function check($className, $parentClassName)
|
||||
{
|
||||
// Check if class is subclass of parent class
|
||||
if(!is_subclass_of($className, $parentClassName)) {
|
||||
throw new \nre\exceptions\ClassNotValidException(
|
||||
$className
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Strip the namespace from a class name.
|
||||
*
|
||||
* @param string $class Name of a class including its namespace
|
||||
* @return Name of the given class without its namespace
|
||||
*/
|
||||
public static function stripNamespace($class)
|
||||
{
|
||||
return array_slice(explode('\\', $class), -1)[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Strip the class type from a class name.
|
||||
*
|
||||
* @param string $className Name of a class
|
||||
* @return Name of the given class without its class type
|
||||
*/
|
||||
public static function stripClassType($className)
|
||||
{
|
||||
return preg_replace('/^(.*)[A-Z][^A-Z]+$/', '$1', $className);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Strip the namespace and the class type of a full class name
|
||||
* to get only its name.
|
||||
*
|
||||
* @param string $class Full name of a class
|
||||
* @return Only the name of the given class
|
||||
*/
|
||||
public static function getClassName($class)
|
||||
{
|
||||
return self::stripClassType(self::stripNamespace($class));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Concatenate strings to a class name following the CamelCase
|
||||
* pattern.
|
||||
*
|
||||
* @param string $className1 Arbitrary number of strings to concat
|
||||
* @return string Class name as CamelCase
|
||||
*/
|
||||
public static function concatClassNames($className1)
|
||||
{
|
||||
return implode('', array_map(
|
||||
function($arg) {
|
||||
return ucfirst(strtolower($arg));
|
||||
},
|
||||
func_get_args()
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Class for safely loading classes.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load a class.
|
||||
*
|
||||
* @throws \nre\exceptions\ClassNotFoundException
|
||||
* @param string $className Name of the class to load
|
||||
*/
|
||||
public static function load($fullClassName)
|
||||
{
|
||||
// Determine folder to look in
|
||||
$className = explode('\\', $fullClassName);
|
||||
$className = array_slice($className, substr_count(\nre\configs\AppConfig::$app['namespace'], '\\'));
|
||||
|
||||
// Determine filename
|
||||
$fileName = ROOT.DS.implode(DS, $className). \nre\configs\CoreConfig::getFileExt('includes');
|
||||
|
||||
|
||||
// Check file
|
||||
if(!file_exists($fileName))
|
||||
{
|
||||
throw new \nre\exceptions\ClassNotFoundException(
|
||||
$fullClassName
|
||||
);
|
||||
}
|
||||
|
||||
// Include file
|
||||
include_once($fileName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check inheritance of a class.
|
||||
*
|
||||
* @throws \nre\exceptions\ClassNotValidException
|
||||
* @param string $className Name of the class to check
|
||||
* @param string $parentClassName Name of the parent class
|
||||
*/
|
||||
public static function check($className, $parentClassName)
|
||||
{
|
||||
// Check if class is subclass of parent class
|
||||
if(!is_subclass_of($className, $parentClassName)) {
|
||||
throw new \nre\exceptions\ClassNotValidException(
|
||||
$className
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Strip the namespace from a class name.
|
||||
*
|
||||
* @param string $class Name of a class including its namespace
|
||||
* @return string Name of the given class without its namespace
|
||||
*/
|
||||
public static function stripNamespace($class)
|
||||
{
|
||||
return array_slice(explode('\\', $class), -1)[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Strip the class type from a class name.
|
||||
*
|
||||
* @param string $className Name of a class
|
||||
* @return string Name of the given class without its class type
|
||||
*/
|
||||
public static function stripClassType($className)
|
||||
{
|
||||
return preg_replace('/^(.*)[A-Z][^A-Z]+$/', '$1', $className);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Strip the namespace and the class type of a full class name
|
||||
* to get only its name.
|
||||
*
|
||||
* @param string $class Full name of a class
|
||||
* @return string Only the name of the given class
|
||||
*/
|
||||
public static function getClassName($class)
|
||||
{
|
||||
return self::stripClassType(self::stripNamespace($class));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Concatenate strings to a class name following the CamelCase
|
||||
* pattern.
|
||||
*
|
||||
* @param string $className1 Arbitrary number of strings to concat
|
||||
* @return string Class name as CamelCase
|
||||
*/
|
||||
public static function concatClassNames($className1)
|
||||
{
|
||||
return implode('', array_map(
|
||||
function($arg) {
|
||||
return ucfirst(strtolower($arg));
|
||||
},
|
||||
func_get_args()
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,85 +1,85 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class to implement a (Controller) Component.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class Component
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the class of a Component.
|
||||
*
|
||||
* @throws \nre\exceptions\ComponentNotFoundException
|
||||
* @throws \nre\exceptions\ComponentNotValidException
|
||||
* @param string $componentName Name of the Component to load
|
||||
*/
|
||||
public static function load($componentName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($componentName);
|
||||
|
||||
try {
|
||||
// Load class
|
||||
ClassLoader::load($className);
|
||||
|
||||
// Validate class
|
||||
ClassLoader::check($className, get_class());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||
throw new \nre\exceptions\ComponentNotValidException($e->getClassName());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
throw new \nre\exceptions\ComponentNotFoundException($e->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate a Component (Factory Pattern).
|
||||
*
|
||||
* @param string $componentName Name of the Component to instantiate
|
||||
*/
|
||||
public static function factory($componentName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($componentName);
|
||||
|
||||
// Construct and return Controller
|
||||
return new $className();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the classname for the given Component name.
|
||||
*
|
||||
* @param string $componentName Component name to get classname of
|
||||
* @return string Classname for the Component name
|
||||
*/
|
||||
private static function getClassName($componentName)
|
||||
{
|
||||
$className = \nre\core\ClassLoader::concatClassNames($componentName, \nre\core\ClassLoader::stripNamespace(get_class()));
|
||||
|
||||
|
||||
return \nre\configs\AppConfig::$app['namespace']."controllers\\components\\$className";
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class to implement a (Controller) Component.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class Component
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the class of a Component.
|
||||
*
|
||||
* @throws \nre\exceptions\ComponentNotFoundException
|
||||
* @throws \nre\exceptions\ComponentNotValidException
|
||||
* @param string $componentName Name of the Component to load
|
||||
*/
|
||||
public static function load($componentName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($componentName);
|
||||
|
||||
try {
|
||||
// Load class
|
||||
ClassLoader::load($className);
|
||||
|
||||
// Validate class
|
||||
ClassLoader::check($className, get_class());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||
throw new \nre\exceptions\ComponentNotValidException($e->getClassName());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
throw new \nre\exceptions\ComponentNotFoundException($e->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate a Component (Factory Pattern).
|
||||
*
|
||||
* @param string $componentName Name of the Component to instantiate
|
||||
*/
|
||||
public static function factory($componentName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($componentName);
|
||||
|
||||
// Construct and return Controller
|
||||
return new $className();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the classname for the given Component name.
|
||||
*
|
||||
* @param string $componentName Component name to get classname of
|
||||
* @return string Classname for the Component name
|
||||
*/
|
||||
private static function getClassName($componentName)
|
||||
{
|
||||
$className = \nre\core\ClassLoader::concatClassNames($componentName, \nre\core\ClassLoader::stripNamespace(get_class()));
|
||||
|
||||
|
||||
return \nre\configs\AppConfig::$app['namespace']."controllers\\components\\$className";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Configuration.
|
||||
*
|
||||
* This class does not hold any configuration value but helps to
|
||||
* determine values that can be hold by AppConfig or CoreConfig.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
final class Config
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a default value.
|
||||
*
|
||||
* @param string $index Index of value to get
|
||||
*/
|
||||
public static function getDefault($index)
|
||||
{
|
||||
if(array_key_exists($index, \nre\configs\AppConfig::$defaults)) {
|
||||
return \nre\configs\AppConfig::$defaults[$index];
|
||||
}
|
||||
if(array_key_exists($index, \nre\configs\CoreConfig::$defaults)) {
|
||||
return \nre\configs\CoreConfig::$defaults[$index];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Configuration.
|
||||
*
|
||||
* This class does not hold any configuration value but helps to
|
||||
* determine values that can be hold by AppConfig or CoreConfig.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
final class Config
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a default value.
|
||||
*
|
||||
* @param string $index Index of value to get
|
||||
*/
|
||||
public static function getDefault($index)
|
||||
{
|
||||
if(array_key_exists($index, \nre\configs\AppConfig::$defaults)) {
|
||||
return \nre\configs\AppConfig::$defaults[$index];
|
||||
}
|
||||
if(array_key_exists($index, \nre\configs\CoreConfig::$defaults)) {
|
||||
return \nre\configs\CoreConfig::$defaults[$index];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,431 +1,431 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for implementing a Controller.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class Controller
|
||||
{
|
||||
/**
|
||||
* Corresponding Agent
|
||||
*
|
||||
* @var Agent
|
||||
*/
|
||||
protected $agent;
|
||||
/**
|
||||
* View of the Controller
|
||||
*
|
||||
* @var View
|
||||
*/
|
||||
protected $view = null;
|
||||
/**
|
||||
* Data to pass to the View
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $viewData = array();
|
||||
/**
|
||||
* Current request
|
||||
*
|
||||
* @var Request
|
||||
*/
|
||||
protected $request = null;
|
||||
/**
|
||||
* Current response
|
||||
*
|
||||
* @var Response
|
||||
*/
|
||||
protected $response = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the class of a Controller.
|
||||
*
|
||||
* @throws \nre\exceptions\ControllerNotFoundException
|
||||
* @throws \nre\exceptions\ControllerNotValidException
|
||||
* @param string $controllerName Name of the Controller to load
|
||||
*/
|
||||
public static function load($controllerName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($controllerName);
|
||||
|
||||
try {
|
||||
// Load class
|
||||
ClassLoader::load($className);
|
||||
|
||||
// Validate class
|
||||
ClassLoader::check($className, get_class());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||
throw new \nre\exceptions\ControllerNotValidException($e->getClassName());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
throw new \nre\exceptions\ControllerNotFoundException($e->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate a Controller (Factory Pattern).
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @param string $controllerName Name of the Controller to instantiate
|
||||
* @param string $layoutName Name of the current Layout
|
||||
* @param string $action Current Action
|
||||
* @param string $agent Corresponding Agent
|
||||
*/
|
||||
public static function factory($controllerName, $layoutName, $action, $agent)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($controllerName);
|
||||
|
||||
// Construct and return Controller
|
||||
return new $className($layoutName, $action, $agent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the classname for the given Controller name.
|
||||
*
|
||||
* @param string $controllerName Controller name to get classname of
|
||||
* @return string Classname for the Controller name
|
||||
*/
|
||||
private static function getClassName($controllerName)
|
||||
{
|
||||
$className = \nre\core\ClassLoader::concatClassNames($controllerName, \nre\core\ClassLoader::stripNamespace(get_class()));
|
||||
|
||||
|
||||
return \nre\configs\AppConfig::$app['namespace']."controllers\\$className";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new Controller.
|
||||
*
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @param string $layoutName Name of the current Layout
|
||||
* @param string $action Current Action
|
||||
* @param Agent $agent Corresponding Agent
|
||||
*/
|
||||
protected function __construct($layoutName, $action, $agent)
|
||||
{
|
||||
// Store values
|
||||
$this->agent = $agent;
|
||||
|
||||
// Load Components
|
||||
$this->loadComponents();
|
||||
|
||||
// Load Models
|
||||
$this->loadModels();
|
||||
|
||||
// Load View
|
||||
$this->loadView($layoutName, $action);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prefilter that is executed before running the Controller.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function preFilter(Request $request, Response $response)
|
||||
{
|
||||
// Request speichern
|
||||
$this->request = $request;
|
||||
|
||||
// Response speichern
|
||||
$this->response = $response;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prefilter that is executed after running the Controller.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function postFilter(Request $request, Response $response)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the Controller.
|
||||
*
|
||||
* This method executes the Action of the Controller defined by
|
||||
* the current Request.
|
||||
*
|
||||
* @throws \nre\exceptions\ParamsNotValidException
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\ActionNotFoundException
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function run(Request $request, Response $response)
|
||||
{
|
||||
// Determine Action
|
||||
$action = $response->getParam(2, 'action');
|
||||
if(!method_exists($this, $action)) {
|
||||
throw new \nre\exceptions\ActionNotFoundException($action);
|
||||
}
|
||||
|
||||
// Determine parameters
|
||||
$params = $response->getParams(3);
|
||||
if(empty($params)) {
|
||||
$params = $request->getParams(3);
|
||||
}
|
||||
|
||||
// Fill missing parameters
|
||||
$rc = new \ReflectionClass($this);
|
||||
$nullParamsCount = $rc->getMethod($action)->getNumberOfParameters() - count($params);
|
||||
$nullParams = ($nullParamsCount > 0 ? array_fill(0, $nullParamsCount, NULL) : array());
|
||||
|
||||
|
||||
// Call Action
|
||||
call_user_func_array(
|
||||
array(
|
||||
$this,
|
||||
$action
|
||||
),
|
||||
array_merge(
|
||||
$params,
|
||||
$nullParams
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the output.
|
||||
*
|
||||
* @param array $viewData Data to pass to the View
|
||||
* @return string Generated output
|
||||
*/
|
||||
public function render($viewData=null)
|
||||
{
|
||||
// Combine given data and data of this Controller
|
||||
$data = $this->viewData;
|
||||
if(!is_null($viewData)) {
|
||||
$data = array_merge($viewData, $data);
|
||||
}
|
||||
|
||||
// Rendern and return output
|
||||
return $this->view->render($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set data for the View.
|
||||
*
|
||||
* @param string $name Key
|
||||
* @param mixed $data Value
|
||||
*/
|
||||
protected function set($name, $data)
|
||||
{
|
||||
$this->viewData[$name] = $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Redirect to the given URL.
|
||||
*
|
||||
* @param string $url Relative URL
|
||||
*/
|
||||
protected function redirect($url)
|
||||
{
|
||||
$url = 'http://'.$_SERVER['HTTP_HOST'].$url;
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if Models of this Controller are loaded and available.
|
||||
*
|
||||
* @param string $modelName Arbitrary number of Models to check
|
||||
* @return bool All given Models are loaded and available
|
||||
*/
|
||||
protected function checkModels($modelName)
|
||||
{
|
||||
foreach(func_get_args() as $modelName)
|
||||
{
|
||||
if(!isset($this->$modelName) || !is_subclass_of($this->$modelName, 'Model')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the View of the Controller
|
||||
*
|
||||
* @return View View of the Controller
|
||||
*/
|
||||
protected function getView()
|
||||
{
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the Components of this Controller.
|
||||
*
|
||||
* @throws \nre\exceptions\ComponentNotValidException
|
||||
* @throws \nre\exceptions\ComponentNotFoundException
|
||||
*/
|
||||
private function loadComponents()
|
||||
{
|
||||
// Determine components
|
||||
$components = array();
|
||||
if(property_exists($this, 'components')) {
|
||||
$components = $this->components;
|
||||
}
|
||||
if(!is_array($components)) {
|
||||
$components = array($components);
|
||||
}
|
||||
// Components of parent classes
|
||||
$parent = $this;
|
||||
while($parent = get_parent_class($parent))
|
||||
{
|
||||
$properties = get_class_vars($parent);
|
||||
if(array_key_exists('components', $properties)) {
|
||||
$components = array_merge($components, $properties['components']);
|
||||
}
|
||||
}
|
||||
|
||||
// Load components
|
||||
foreach($components as &$component)
|
||||
{
|
||||
// Load class
|
||||
Component::load($component);
|
||||
|
||||
// Construct component
|
||||
$componentName = ucfirst(strtolower($component));
|
||||
$this->$componentName = Component::factory($component);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the Models of this Controller.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
*/
|
||||
protected function loadModels()
|
||||
{
|
||||
// Determine Models
|
||||
$explicit = false;
|
||||
$models = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class($this)));
|
||||
if(property_exists($this, 'models'))
|
||||
{
|
||||
$models = $this->models;
|
||||
$explicit = true;
|
||||
}
|
||||
if(!is_array($models)) {
|
||||
$models = array($models);
|
||||
}
|
||||
// Models of parent classes
|
||||
$parent = $this;
|
||||
while($parent = get_parent_class($parent))
|
||||
{
|
||||
$properties = get_class_vars($parent);
|
||||
if(array_key_exists('models', $properties)) {
|
||||
$models = array_merge($models, $properties['models']);
|
||||
}
|
||||
}
|
||||
$models = array_unique($models);
|
||||
|
||||
// Load Models
|
||||
foreach($models as &$model)
|
||||
{
|
||||
try {
|
||||
// Load class
|
||||
Model::load($model);
|
||||
|
||||
// Construct Model
|
||||
$modelName = ucfirst(strtolower($model));
|
||||
$this->$modelName = Model::factory($model);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotValidException $e) {
|
||||
if($explicit) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotFoundException $e) {
|
||||
if($explicit) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the View of this Controller.
|
||||
*
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @param string $layoutName Name of the current Layout
|
||||
* @param string $action Current Action
|
||||
*/
|
||||
protected function loadView($layoutName, $action)
|
||||
{
|
||||
// Check Layout name
|
||||
if(is_null($layoutName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine controller name
|
||||
$controllerName = \nre\core\ClassLoader::getClassName(get_class($this));
|
||||
|
||||
|
||||
// Load view
|
||||
$isToplevel = is_subclass_of($this->agent, '\nre\agents\ToplevelAgent');
|
||||
$this->view = View::loadAndFactory($layoutName, $controllerName, $action, $isToplevel);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for implementing a Controller.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class Controller
|
||||
{
|
||||
/**
|
||||
* Corresponding Agent
|
||||
*
|
||||
* @var Agent
|
||||
*/
|
||||
protected $agent;
|
||||
/**
|
||||
* View of the Controller
|
||||
*
|
||||
* @var View
|
||||
*/
|
||||
protected $view = null;
|
||||
/**
|
||||
* Data to pass to the View
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $viewData = array();
|
||||
/**
|
||||
* Current request
|
||||
*
|
||||
* @var Request
|
||||
*/
|
||||
protected $request = null;
|
||||
/**
|
||||
* Current response
|
||||
*
|
||||
* @var Response
|
||||
*/
|
||||
protected $response = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the class of a Controller.
|
||||
*
|
||||
* @throws \nre\exceptions\ControllerNotFoundException
|
||||
* @throws \nre\exceptions\ControllerNotValidException
|
||||
* @param string $controllerName Name of the Controller to load
|
||||
*/
|
||||
public static function load($controllerName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($controllerName);
|
||||
|
||||
try {
|
||||
// Load class
|
||||
ClassLoader::load($className);
|
||||
|
||||
// Validate class
|
||||
ClassLoader::check($className, get_class());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||
throw new \nre\exceptions\ControllerNotValidException($e->getClassName());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
throw new \nre\exceptions\ControllerNotFoundException($e->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate a Controller (Factory Pattern).
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @param string $controllerName Name of the Controller to instantiate
|
||||
* @param string $layoutName Name of the current Layout
|
||||
* @param string $action Current Action
|
||||
* @param string $agent Corresponding Agent
|
||||
*/
|
||||
public static function factory($controllerName, $layoutName, $action, $agent)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($controllerName);
|
||||
|
||||
// Construct and return Controller
|
||||
return new $className($layoutName, $action, $agent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the classname for the given Controller name.
|
||||
*
|
||||
* @param string $controllerName Controller name to get classname of
|
||||
* @return string Classname for the Controller name
|
||||
*/
|
||||
private static function getClassName($controllerName)
|
||||
{
|
||||
$className = \nre\core\ClassLoader::concatClassNames($controllerName, \nre\core\ClassLoader::stripNamespace(get_class()));
|
||||
|
||||
|
||||
return \nre\configs\AppConfig::$app['namespace']."controllers\\$className";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new Controller.
|
||||
*
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @param string $layoutName Name of the current Layout
|
||||
* @param string $action Current Action
|
||||
* @param Agent $agent Corresponding Agent
|
||||
*/
|
||||
protected function __construct($layoutName, $action, $agent)
|
||||
{
|
||||
// Store values
|
||||
$this->agent = $agent;
|
||||
|
||||
// Load Components
|
||||
$this->loadComponents();
|
||||
|
||||
// Load Models
|
||||
$this->loadModels();
|
||||
|
||||
// Load View
|
||||
$this->loadView($layoutName, $action);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prefilter that is executed before running the Controller.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function preFilter(Request $request, Response $response)
|
||||
{
|
||||
// Request speichern
|
||||
$this->request = $request;
|
||||
|
||||
// Response speichern
|
||||
$this->response = $response;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prefilter that is executed after running the Controller.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function postFilter(Request $request, Response $response)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the Controller.
|
||||
*
|
||||
* This method executes the Action of the Controller defined by
|
||||
* the current Request.
|
||||
*
|
||||
* @throws \nre\exceptions\ParamsNotValidException
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\ActionNotFoundException
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function run(Request $request, Response $response)
|
||||
{
|
||||
// Determine Action
|
||||
$action = $response->getParam(2, 'action');
|
||||
if(!method_exists($this, $action)) {
|
||||
throw new \nre\exceptions\ActionNotFoundException($action);
|
||||
}
|
||||
|
||||
// Determine parameters
|
||||
$params = $response->getParams(3);
|
||||
if(empty($params)) {
|
||||
$params = $request->getParams(3);
|
||||
}
|
||||
|
||||
// Fill missing parameters
|
||||
$rc = new \ReflectionClass($this);
|
||||
$nullParamsCount = $rc->getMethod($action)->getNumberOfParameters() - count($params);
|
||||
$nullParams = ($nullParamsCount > 0 ? array_fill(0, $nullParamsCount, NULL) : array());
|
||||
|
||||
|
||||
// Call Action
|
||||
call_user_func_array(
|
||||
array(
|
||||
$this,
|
||||
$action
|
||||
),
|
||||
array_merge(
|
||||
$params,
|
||||
$nullParams
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the output.
|
||||
*
|
||||
* @param array $viewData Data to pass to the View
|
||||
* @return string Generated output
|
||||
*/
|
||||
public function render($viewData=null)
|
||||
{
|
||||
// Combine given data and data of this Controller
|
||||
$data = $this->viewData;
|
||||
if(!is_null($viewData)) {
|
||||
$data = array_merge($viewData, $data);
|
||||
}
|
||||
|
||||
// Rendern and return output
|
||||
return $this->view->render($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set data for the View.
|
||||
*
|
||||
* @param string $name Key
|
||||
* @param mixed $data Value
|
||||
*/
|
||||
protected function set($name, $data)
|
||||
{
|
||||
$this->viewData[$name] = $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Redirect to the given URL.
|
||||
*
|
||||
* @param string $url Relative URL
|
||||
*/
|
||||
protected function redirect($url)
|
||||
{
|
||||
$url = 'http://'.$_SERVER['HTTP_HOST'].$url;
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if Models of this Controller are loaded and available.
|
||||
*
|
||||
* @param string $modelName Arbitrary number of Models to check
|
||||
* @return bool All given Models are loaded and available
|
||||
*/
|
||||
protected function checkModels($modelName)
|
||||
{
|
||||
foreach(func_get_args() as $modelName)
|
||||
{
|
||||
if(!isset($this->$modelName) || !is_subclass_of($this->$modelName, 'Model')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the View of the Controller
|
||||
*
|
||||
* @return View View of the Controller
|
||||
*/
|
||||
protected function getView()
|
||||
{
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the Components of this Controller.
|
||||
*
|
||||
* @throws \nre\exceptions\ComponentNotValidException
|
||||
* @throws \nre\exceptions\ComponentNotFoundException
|
||||
*/
|
||||
private function loadComponents()
|
||||
{
|
||||
// Determine components
|
||||
$components = array();
|
||||
if(property_exists($this, 'components')) {
|
||||
$components = $this->components;
|
||||
}
|
||||
if(!is_array($components)) {
|
||||
$components = array($components);
|
||||
}
|
||||
// Components of parent classes
|
||||
$parent = $this;
|
||||
while($parent = get_parent_class($parent))
|
||||
{
|
||||
$properties = get_class_vars($parent);
|
||||
if(array_key_exists('components', $properties)) {
|
||||
$components = array_merge($components, $properties['components']);
|
||||
}
|
||||
}
|
||||
|
||||
// Load components
|
||||
foreach($components as &$component)
|
||||
{
|
||||
// Load class
|
||||
Component::load($component);
|
||||
|
||||
// Construct component
|
||||
$componentName = ucfirst(strtolower($component));
|
||||
$this->$componentName = Component::factory($component);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the Models of this Controller.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
*/
|
||||
protected function loadModels()
|
||||
{
|
||||
// Determine Models
|
||||
$explicit = false;
|
||||
$models = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class($this)));
|
||||
if(property_exists($this, 'models'))
|
||||
{
|
||||
$models = $this->models;
|
||||
$explicit = true;
|
||||
}
|
||||
if(!is_array($models)) {
|
||||
$models = array($models);
|
||||
}
|
||||
// Models of parent classes
|
||||
$parent = $this;
|
||||
while($parent = get_parent_class($parent))
|
||||
{
|
||||
$properties = get_class_vars($parent);
|
||||
if(array_key_exists('models', $properties)) {
|
||||
$models = array_merge($models, $properties['models']);
|
||||
}
|
||||
}
|
||||
$models = array_unique($models);
|
||||
|
||||
// Load Models
|
||||
foreach($models as &$model)
|
||||
{
|
||||
try {
|
||||
// Load class
|
||||
Model::load($model);
|
||||
|
||||
// Construct Model
|
||||
$modelName = ucfirst(strtolower($model));
|
||||
$this->$modelName = Model::factory($model);
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotValidException $e) {
|
||||
if($explicit) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
catch(\nre\exceptions\ModelNotFoundException $e) {
|
||||
if($explicit) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the View of this Controller.
|
||||
*
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @param string $layoutName Name of the current Layout
|
||||
* @param string $action Current Action
|
||||
*/
|
||||
protected function loadView($layoutName, $action)
|
||||
{
|
||||
// Check Layout name
|
||||
if(is_null($layoutName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine controller name
|
||||
$controllerName = \nre\core\ClassLoader::getClassName(get_class($this));
|
||||
|
||||
|
||||
// Load view
|
||||
$isToplevel = is_subclass_of($this->agent, '\nre\agents\ToplevelAgent');
|
||||
$this->view = View::loadAndFactory($layoutName, $controllerName, $action, $isToplevel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
186
core/Driver.inc
186
core/Driver.inc
|
@ -1,97 +1,97 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for implementing a Driver.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class Driver
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the class of a Driver.
|
||||
*
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @param string $driverName Name of the Driver to load
|
||||
*/
|
||||
public static function load($driverName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($driverName);
|
||||
|
||||
try {
|
||||
// Load class
|
||||
ClassLoader::load($className);
|
||||
|
||||
// Validate class
|
||||
ClassLoader::check($className, get_class());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||
throw new \nre\exceptions\DriverNotValidException($e->getClassName());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
throw new \nre\exceptions\DriverNotFoundException($e->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate a Driver (Factory Pattern).
|
||||
*
|
||||
* @param string $driverName Name of the Driver to instantiate
|
||||
* @param array $config Configuration settings
|
||||
*/
|
||||
public static function factory($driverName, $config)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($driverName);
|
||||
|
||||
|
||||
// Construct and return Driver
|
||||
return $className::singleton($config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the classname for the given Driver name.
|
||||
*
|
||||
* @param string $driverName Driver name to get classname of
|
||||
* @return string Classname fore the Driver name
|
||||
*/
|
||||
private static function getClassName($driverName)
|
||||
{
|
||||
$className = ClassLoader::concatClassNames($driverName, ClassLoader::stripNamespace(get_class()));
|
||||
|
||||
|
||||
return "\\nre\\drivers\\$className";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new Driver.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for implementing a Driver.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class Driver
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the class of a Driver.
|
||||
*
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @param string $driverName Name of the Driver to load
|
||||
*/
|
||||
public static function load($driverName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($driverName);
|
||||
|
||||
try {
|
||||
// Load class
|
||||
ClassLoader::load($className);
|
||||
|
||||
// Validate class
|
||||
ClassLoader::check($className, get_class());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||
throw new \nre\exceptions\DriverNotValidException($e->getClassName());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
throw new \nre\exceptions\DriverNotFoundException($e->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate a Driver (Factory Pattern).
|
||||
*
|
||||
* @param string $driverName Name of the Driver to instantiate
|
||||
* @param array $config Configuration settings
|
||||
*/
|
||||
public static function factory($driverName, $config)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($driverName);
|
||||
|
||||
|
||||
// Construct and return Driver
|
||||
return $className::singleton($config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the classname for the given Driver name.
|
||||
*
|
||||
* @param string $driverName Driver name to get classname of
|
||||
* @return string Classname fore the Driver name
|
||||
*/
|
||||
private static function getClassName($driverName)
|
||||
{
|
||||
$className = ClassLoader::concatClassNames($driverName, ClassLoader::stripNamespace(get_class()));
|
||||
|
||||
|
||||
return "\\nre\\drivers\\$className";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new Driver.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,65 +1,65 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Exception class.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Exception extends \Exception
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $message Error message
|
||||
* @param int $code Error code
|
||||
* @param string $name Name to insert
|
||||
*/
|
||||
function __construct($message, $code, $name=null)
|
||||
{
|
||||
parent::__construct(
|
||||
$this->concat(
|
||||
$message,
|
||||
$name
|
||||
),
|
||||
$code
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Insert the name in a message
|
||||
*
|
||||
* @param string $message Error message
|
||||
* @param string $name Name to insert
|
||||
*/
|
||||
private function concat($message, $name)
|
||||
{
|
||||
if(is_null($name)) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
|
||||
return "$message: $name";
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Exception class.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Exception extends \Exception
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $message Error message
|
||||
* @param int $code Error code
|
||||
* @param string $name Name to insert
|
||||
*/
|
||||
function __construct($message, $code, $name=null)
|
||||
{
|
||||
parent::__construct(
|
||||
$this->concat(
|
||||
$message,
|
||||
$name
|
||||
),
|
||||
$code
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Insert the name in a message
|
||||
*
|
||||
* @param string $message Error message
|
||||
* @param string $name Name to insert
|
||||
*/
|
||||
private function concat($message, $name)
|
||||
{
|
||||
if(is_null($name)) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
|
||||
return "$message: $name";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
618
core/Linker.inc
618
core/Linker.inc
|
@ -1,313 +1,313 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Class to create web links based on the current request.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Linker
|
||||
{
|
||||
/**
|
||||
* Current request
|
||||
*
|
||||
* @var \nre\core\Request
|
||||
*/
|
||||
private $request;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new linker.
|
||||
*
|
||||
* @param \nre\core\Request $request Current request
|
||||
*/
|
||||
function __construct(\nre\requests\WebRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Mask parameters to be used in an URL.
|
||||
*
|
||||
* @param string $param1 First parameter
|
||||
* @return string Masked parameters as string
|
||||
*/
|
||||
public static function createLinkParam($param1)
|
||||
{
|
||||
return implode(
|
||||
\nre\configs\CoreConfig::$classes['linker']['url']['delimiter'],
|
||||
call_user_func_array(
|
||||
'\nre\core\Linker::createLinkParams',
|
||||
func_get_args()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mask parameters to be used in an URL.
|
||||
*
|
||||
* @param string $param1 First parameter
|
||||
* @return string Masked parameters as array
|
||||
*/
|
||||
public static function createLinkParams($param1)
|
||||
{
|
||||
// Parameters
|
||||
$linkParams = array();
|
||||
$params = func_get_args();
|
||||
|
||||
foreach($params as $param)
|
||||
{
|
||||
// Delete critical signs
|
||||
$specials = array('/', '?', '&', '#');
|
||||
foreach($specials as &$special) {
|
||||
$param = str_replace($special, '', $param);
|
||||
}
|
||||
|
||||
// Process parameter
|
||||
$param = str_replace(
|
||||
' ',
|
||||
\nre\configs\CoreConfig::$classes['linker']['url']['delimiter'],
|
||||
substr(
|
||||
$param,
|
||||
0,
|
||||
\nre\configs\CoreConfig::$classes['linker']['url']['length']
|
||||
)
|
||||
);
|
||||
|
||||
// Encode parameter
|
||||
$linkParams[] = $param;
|
||||
}
|
||||
|
||||
|
||||
// Return link parameters
|
||||
return $linkParams;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a web link.
|
||||
*
|
||||
* @param array $params Parameters to use
|
||||
* @param int $offset Ignore first parameters
|
||||
* @param bool $exclusiveParams Use only the given parameters
|
||||
* @param array $getParams GET-parameter to use
|
||||
* @param bool $exclusiveGetParams Use only the given GET-parameters
|
||||
* @param string $anchor Target anchor
|
||||
* @param bool $absolute Include hostname etc. for an absolute URL
|
||||
* @return string Created link
|
||||
*/
|
||||
public function link($params=null, $offset=0, $exclusiveParams=true, $getParams=null, $exclusiveGetParams=true, $anchor=null, $absolute=false)
|
||||
{
|
||||
// Make current request to response
|
||||
$response = new \nre\responses\WebResponse();
|
||||
|
||||
|
||||
// Check parameters
|
||||
if(is_null($params)) {
|
||||
$params = array();
|
||||
}
|
||||
elseif(!is_array($params)) {
|
||||
$params = array($params);
|
||||
}
|
||||
|
||||
// Set parameters from request
|
||||
$reqParams = array_slice($this->request->getParams(), 1, $offset);
|
||||
if(count($reqParams) < $offset && $offset > 0) {
|
||||
$reqParams[] = $this->request->getParam(1, 'intermediate');
|
||||
}
|
||||
if(count($reqParams) < $offset && $offset > 1) {
|
||||
$reqParams[] = $this->request->getParam(2, 'action');
|
||||
}
|
||||
$params = array_merge($reqParams, $params);
|
||||
|
||||
// Use Layout
|
||||
$layout = \nre\configs\AppConfig::$defaults['toplevel'];
|
||||
if(!empty($getParams) && array_key_exists('layout', $getParams)) {
|
||||
$layout = $getParams['layout'];
|
||||
}
|
||||
array_unshift($params, $layout);
|
||||
|
||||
// Use parameters from request only
|
||||
if(!$exclusiveParams)
|
||||
{
|
||||
$params = array_merge(
|
||||
$params,
|
||||
array_slice(
|
||||
$this->request->getParams(),
|
||||
count($params)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Encode parameters
|
||||
$params = array_map('rawurlencode', $params);
|
||||
|
||||
// Set parameters
|
||||
call_user_func_array(
|
||||
array(
|
||||
$response,
|
||||
'addParams'
|
||||
),
|
||||
$params
|
||||
);
|
||||
|
||||
|
||||
// Check GET-parameters
|
||||
if(is_null($getParams)) {
|
||||
$getParams = array();
|
||||
}
|
||||
elseif(!is_array($params)) {
|
||||
$params = array($params);
|
||||
}
|
||||
if(!$exclusiveGetParams)
|
||||
{
|
||||
$getParams = array_merge(
|
||||
$this->request->getGetParams(),
|
||||
$getParams
|
||||
);
|
||||
}
|
||||
|
||||
// Set GET-parameters
|
||||
$response->addGetParams($getParams);
|
||||
|
||||
|
||||
// Create and return link
|
||||
return self::createLink($this->request, $response, $anchor, $absolute);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a link from an URL.
|
||||
*
|
||||
* @param string $url URL to create link from
|
||||
* @param bool $absolute Create absolute URL
|
||||
* @return string Created link
|
||||
*/
|
||||
public function hardlink($url, $absolute=false)
|
||||
{
|
||||
return $this->createUrl($url, $this->request, $absolute);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a link.
|
||||
*
|
||||
* @param \nre\core\Request $request Current request
|
||||
* @param \nre\core\Response $response Current response
|
||||
* @param string $anchor Anchor on target
|
||||
* @param bool $absolute Create absolute link
|
||||
* @return string Created link
|
||||
*/
|
||||
private static function createLink(Request $request, Response $response, $anchor=null, $absolute=false)
|
||||
{
|
||||
// Check response
|
||||
if(is_null($response)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// Get parameters
|
||||
$params = $response->getParams(1);
|
||||
|
||||
// Check Action
|
||||
if(count($params) == 2 && $params[1] == \nre\configs\CoreConfig::$defaults['action']) {
|
||||
array_pop($params);
|
||||
}
|
||||
|
||||
// Set parameters
|
||||
$link = implode('/', $params);
|
||||
|
||||
// Apply reverse-routes
|
||||
$link = $request->applyReverseRoutes($link);
|
||||
|
||||
|
||||
// Get GET-parameters
|
||||
$getParams = $response->getGetParams();
|
||||
|
||||
// Layout überprüfen
|
||||
if(array_key_exists('layout', $getParams) && $getParams['layout'] == \nre\configs\AppConfig::$defaults['toplevel']) {
|
||||
unset($getParams['layout']);
|
||||
}
|
||||
|
||||
// Set GET-parameters
|
||||
if(array_key_exists('url', $getParams)) {
|
||||
unset($getParams['url']);
|
||||
}
|
||||
if(count($getParams) > 0) {
|
||||
$link .= '?'.http_build_query($getParams);
|
||||
}
|
||||
|
||||
// Add anchor
|
||||
if(!is_null($anchor)) {
|
||||
$link .= "#$anchor";
|
||||
}
|
||||
|
||||
|
||||
// Create URL
|
||||
$url = self::createUrl($link, $request, $absolute);
|
||||
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adapt a link to the environment.
|
||||
*
|
||||
* @param string $url URL
|
||||
* @param \nre\core\Request $request Current request
|
||||
* @param bool $absolute Create absolute URL
|
||||
* @return string Adapted URL
|
||||
*/
|
||||
private static function createUrl($url, Request $request, $absolute=false)
|
||||
{
|
||||
// Variables
|
||||
$server = $_SERVER['SERVER_NAME'];
|
||||
$uri = $_SERVER['REQUEST_URI'];
|
||||
$prefix = '';
|
||||
|
||||
|
||||
// Determine prefix
|
||||
$ppos = array(strlen($uri));
|
||||
if(($p = strpos($uri, '/'.$request->getParam(1, 'intermediate'))) !== false) {
|
||||
$ppos[] = $p;
|
||||
}
|
||||
$prefix = substr($uri, 0, min($ppos));
|
||||
|
||||
// Create absolute URL
|
||||
if($absolute) {
|
||||
$prefix = "http://$server/".trim($prefix, '/');
|
||||
}
|
||||
|
||||
// Put URL together
|
||||
$url = rtrim($prefix, '/').'/'.ltrim($url, '/');
|
||||
|
||||
|
||||
// Return URL
|
||||
return $url;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Class to create web links based on the current request.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Linker
|
||||
{
|
||||
/**
|
||||
* Current request
|
||||
*
|
||||
* @var Request
|
||||
*/
|
||||
private $request;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new linker.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
*/
|
||||
function __construct(\nre\requests\WebRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Mask parameters to be used in an URL.
|
||||
*
|
||||
* @param string $param1 First parameter
|
||||
* @return string Masked parameters as string
|
||||
*/
|
||||
public static function createLinkParam($param1)
|
||||
{
|
||||
return implode(
|
||||
\nre\configs\CoreConfig::$classes['linker']['url']['delimiter'],
|
||||
call_user_func_array(
|
||||
'\nre\core\Linker::createLinkParams',
|
||||
func_get_args()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mask parameters to be used in an URL.
|
||||
*
|
||||
* @param string $param1 First parameter
|
||||
* @return string Masked parameters as array
|
||||
*/
|
||||
public static function createLinkParams($param1)
|
||||
{
|
||||
// Parameters
|
||||
$linkParams = array();
|
||||
$params = func_get_args();
|
||||
|
||||
foreach($params as $param)
|
||||
{
|
||||
// Delete critical signs
|
||||
$specials = array('/', '?', '&', '#');
|
||||
foreach($specials as &$special) {
|
||||
$param = str_replace($special, '', $param);
|
||||
}
|
||||
|
||||
// Process parameter
|
||||
$param = str_replace(
|
||||
' ',
|
||||
\nre\configs\CoreConfig::$classes['linker']['url']['delimiter'],
|
||||
substr(
|
||||
$param,
|
||||
0,
|
||||
\nre\configs\CoreConfig::$classes['linker']['url']['length']
|
||||
)
|
||||
);
|
||||
|
||||
// Encode parameter
|
||||
$linkParams[] = $param;
|
||||
}
|
||||
|
||||
|
||||
// Return link parameters
|
||||
return $linkParams;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a web link.
|
||||
*
|
||||
* @param array $params Parameters to use
|
||||
* @param int $offset Ignore first parameters
|
||||
* @param bool $exclusiveParams Use only the given parameters
|
||||
* @param array $getParams GET-parameter to use
|
||||
* @param bool $exclusiveGetParams Use only the given GET-parameters
|
||||
* @param string $anchor Target anchor
|
||||
* @param bool $absolute Include hostname etc. for an absolute URL
|
||||
* @return string Created link
|
||||
*/
|
||||
public function link($params=null, $offset=0, $exclusiveParams=true, $getParams=null, $exclusiveGetParams=true, $anchor=null, $absolute=false)
|
||||
{
|
||||
// Make current request to response
|
||||
$response = new \nre\responses\WebResponse();
|
||||
|
||||
|
||||
// Check parameters
|
||||
if(is_null($params)) {
|
||||
$params = array();
|
||||
}
|
||||
elseif(!is_array($params)) {
|
||||
$params = array($params);
|
||||
}
|
||||
|
||||
// Set parameters from request
|
||||
$reqParams = array_slice($this->request->getParams(), 1, $offset);
|
||||
if(count($reqParams) < $offset && $offset > 0) {
|
||||
$reqParams[] = $this->request->getParam(1, 'intermediate');
|
||||
}
|
||||
if(count($reqParams) < $offset && $offset > 1) {
|
||||
$reqParams[] = $this->request->getParam(2, 'action');
|
||||
}
|
||||
$params = array_merge($reqParams, $params);
|
||||
|
||||
// Use Layout
|
||||
$layout = \nre\configs\AppConfig::$defaults['toplevel'];
|
||||
if(!empty($getParams) && array_key_exists('layout', $getParams)) {
|
||||
$layout = $getParams['layout'];
|
||||
}
|
||||
array_unshift($params, $layout);
|
||||
|
||||
// Use parameters from request only
|
||||
if(!$exclusiveParams)
|
||||
{
|
||||
$params = array_merge(
|
||||
$params,
|
||||
array_slice(
|
||||
$this->request->getParams(),
|
||||
count($params)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Encode parameters
|
||||
$params = array_map('rawurlencode', $params);
|
||||
|
||||
// Set parameters
|
||||
call_user_func_array(
|
||||
array(
|
||||
$response,
|
||||
'addParams'
|
||||
),
|
||||
$params
|
||||
);
|
||||
|
||||
|
||||
// Check GET-parameters
|
||||
if(is_null($getParams)) {
|
||||
$getParams = array();
|
||||
}
|
||||
elseif(!is_array($params)) {
|
||||
$params = array($params);
|
||||
}
|
||||
if(!$exclusiveGetParams)
|
||||
{
|
||||
$getParams = array_merge(
|
||||
$this->request->getGetParams(),
|
||||
$getParams
|
||||
);
|
||||
}
|
||||
|
||||
// Set GET-parameters
|
||||
$response->addGetParams($getParams);
|
||||
|
||||
|
||||
// Create and return link
|
||||
return self::createLink($this->request, $response, $anchor, $absolute);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a link from an URL.
|
||||
*
|
||||
* @param string $url URL to create link from
|
||||
* @param bool $absolute Create absolute URL
|
||||
* @return string Created link
|
||||
*/
|
||||
public function hardlink($url, $absolute=false)
|
||||
{
|
||||
return $this->createUrl($url, $this->request, $absolute);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a link.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
* @param string $anchor Anchor on target
|
||||
* @param bool $absolute Create absolute link
|
||||
* @return string Created link
|
||||
*/
|
||||
private static function createLink(Request $request, Response $response, $anchor=null, $absolute=false)
|
||||
{
|
||||
// Check response
|
||||
if(is_null($response)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// Get parameters
|
||||
$params = $response->getParams(1);
|
||||
|
||||
// Check Action
|
||||
if(count($params) == 2 && $params[1] == \nre\configs\CoreConfig::$defaults['action']) {
|
||||
array_pop($params);
|
||||
}
|
||||
|
||||
// Set parameters
|
||||
$link = implode('/', $params);
|
||||
|
||||
// Apply reverse-routes
|
||||
$link = $request->applyReverseRoutes($link);
|
||||
|
||||
|
||||
// Get GET-parameters
|
||||
$getParams = $response->getGetParams();
|
||||
|
||||
// Layout überprüfen
|
||||
if(array_key_exists('layout', $getParams) && $getParams['layout'] == \nre\configs\AppConfig::$defaults['toplevel']) {
|
||||
unset($getParams['layout']);
|
||||
}
|
||||
|
||||
// Set GET-parameters
|
||||
if(array_key_exists('url', $getParams)) {
|
||||
unset($getParams['url']);
|
||||
}
|
||||
if(count($getParams) > 0) {
|
||||
$link .= '?'.http_build_query($getParams);
|
||||
}
|
||||
|
||||
// Add anchor
|
||||
if(!is_null($anchor)) {
|
||||
$link .= "#$anchor";
|
||||
}
|
||||
|
||||
|
||||
// Create URL
|
||||
$url = self::createUrl($link, $request, $absolute);
|
||||
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adapt a link to the environment.
|
||||
*
|
||||
* @param string $url URL
|
||||
* @param Request $request Current request
|
||||
* @param bool $absolute Create absolute URL
|
||||
* @return string Adapted URL
|
||||
*/
|
||||
private static function createUrl($url, Request $request, $absolute=false)
|
||||
{
|
||||
// Variables
|
||||
$server = $_SERVER['SERVER_NAME'];
|
||||
$uri = $_SERVER['REQUEST_URI'];
|
||||
$prefix = '';
|
||||
|
||||
|
||||
// Determine prefix
|
||||
$ppos = array(strlen($uri));
|
||||
if(($p = strpos($uri, '/'.$request->getParam(1, 'intermediate'))) !== false) {
|
||||
$ppos[] = $p;
|
||||
}
|
||||
$prefix = substr($uri, 0, min($ppos));
|
||||
|
||||
// Create absolute URL
|
||||
if($absolute) {
|
||||
$prefix = "http://$server/".trim($prefix, '/');
|
||||
}
|
||||
|
||||
// Put URL together
|
||||
$url = rtrim($prefix, '/').'/'.ltrim($url, '/');
|
||||
|
||||
|
||||
// Return URL
|
||||
return $url;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
278
core/Logger.inc
278
core/Logger.inc
|
@ -1,143 +1,143 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Class to log messages to different targets.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Logger
|
||||
{
|
||||
/**
|
||||
* Log mode: Detect automatic
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LOGMODE_AUTO = 0;
|
||||
/**
|
||||
* Log mode: Print to screen
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LOGMODE_SCREEN = 1;
|
||||
/**
|
||||
* Log mode: Use PHP-logging mechanism
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LOGMODE_PHP = 2;
|
||||
|
||||
/**
|
||||
* Do not auto-log to screen
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $autoLogToScreenDisabled = false;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new logger.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Log a message.
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param int $logMode Log mode to use
|
||||
*/
|
||||
public function log($message, $logMode=self::LOGMODE_SCREEN)
|
||||
{
|
||||
// Choose log mode automatically
|
||||
if($logMode == self::LOGMODE_AUTO) {
|
||||
$logMode = $this->getAutoLogMode();
|
||||
}
|
||||
|
||||
// Print message to screen
|
||||
if($logMode & self::LOGMODE_SCREEN) {
|
||||
$this->logToScreen($message);
|
||||
}
|
||||
|
||||
// Use PHP-logging mechanism
|
||||
if($logMode & self::LOGMODE_PHP) {
|
||||
$this->logToPhp($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disable logging to screen when the log mode is automatically
|
||||
* detected.
|
||||
*/
|
||||
public function disableAutoLogToScreen()
|
||||
{
|
||||
$this->autoLogToScreenDisabled = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Print a message to screen.
|
||||
*
|
||||
* @param string $message Message to print
|
||||
*/
|
||||
private function logToScreen($message)
|
||||
{
|
||||
echo "$message<br>\n";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Log a message by using PHP-logging mechanism.
|
||||
*
|
||||
* @param string $message Message to log
|
||||
*/
|
||||
private function logToPhp($message)
|
||||
{
|
||||
error_log($message, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detect log mode automatically by distinguishing between
|
||||
* production and test environment.
|
||||
*
|
||||
* @return int Automatically detected log mode
|
||||
*/
|
||||
private function getAutoLogMode()
|
||||
{
|
||||
return ($this->isLocalhost() && !$this->autoLogToScreenDisabled) ? self::LOGMODE_SCREEN : self::LOGMODE_PHP;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detect if the server is running as localhost without domain.
|
||||
*
|
||||
* @return boolean Wheather server is running as localhost or not
|
||||
*/
|
||||
private function isLocalhost()
|
||||
{
|
||||
return ($_SERVER['SERVER_ADDR'] == '127.0.0.1' || $_SERVER['SERVER_ADDR'] = '::1');
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Class to log messages to different targets.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Logger
|
||||
{
|
||||
/**
|
||||
* Log mode: Detect automatic
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LOGMODE_AUTO = 0;
|
||||
/**
|
||||
* Log mode: Print to screen
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LOGMODE_SCREEN = 1;
|
||||
/**
|
||||
* Log mode: Use PHP-logging mechanism
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LOGMODE_PHP = 2;
|
||||
|
||||
/**
|
||||
* Do not auto-log to screen
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $autoLogToScreenDisabled = false;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new logger.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Log a message.
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param int $logMode Log mode to use
|
||||
*/
|
||||
public function log($message, $logMode=self::LOGMODE_SCREEN)
|
||||
{
|
||||
// Choose log mode automatically
|
||||
if($logMode == self::LOGMODE_AUTO) {
|
||||
$logMode = $this->getAutoLogMode();
|
||||
}
|
||||
|
||||
// Print message to screen
|
||||
if($logMode & self::LOGMODE_SCREEN) {
|
||||
$this->logToScreen($message);
|
||||
}
|
||||
|
||||
// Use PHP-logging mechanism
|
||||
if($logMode & self::LOGMODE_PHP) {
|
||||
$this->logToPhp($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disable logging to screen when the log mode is automatically
|
||||
* detected.
|
||||
*/
|
||||
public function disableAutoLogToScreen()
|
||||
{
|
||||
$this->autoLogToScreenDisabled = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Print a message to screen.
|
||||
*
|
||||
* @param string $message Message to print
|
||||
*/
|
||||
private function logToScreen($message)
|
||||
{
|
||||
echo "$message<br>\n";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Log a message by using PHP-logging mechanism.
|
||||
*
|
||||
* @param string $message Message to log
|
||||
*/
|
||||
private function logToPhp($message)
|
||||
{
|
||||
error_log($message, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detect log mode automatically by distinguishing between
|
||||
* production and test environment.
|
||||
*
|
||||
* @return int Automatically detected log mode
|
||||
*/
|
||||
private function getAutoLogMode()
|
||||
{
|
||||
return ($this->isLocalhost() && !$this->autoLogToScreenDisabled) ? self::LOGMODE_SCREEN : self::LOGMODE_PHP;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detect if the server is running as localhost without domain.
|
||||
*
|
||||
* @return boolean Wheather server is running as localhost or not
|
||||
*/
|
||||
private function isLocalhost()
|
||||
{
|
||||
return ($_SERVER['SERVER_ADDR'] == '127.0.0.1' || $_SERVER['SERVER_ADDR'] = '::1');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
274
core/Model.inc
274
core/Model.inc
|
@ -1,141 +1,141 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for implementing a Model.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the class of a Model.
|
||||
*
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @param string $modelName Name of the Model to load
|
||||
*/
|
||||
public static function load($modelName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($modelName);
|
||||
|
||||
try {
|
||||
// Load class
|
||||
ClassLoader::load($className);
|
||||
|
||||
// Validate class
|
||||
ClassLoader::check($className, get_class());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||
throw new \nre\exceptions\ModelNotValidException($e->getClassName());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
throw new \nre\exceptions\ModelNotFoundException($e->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate a Model (Factory Pattern).
|
||||
*
|
||||
* @param string $modelName Name of the Model to instantiate
|
||||
*/
|
||||
public static function factory($modelName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($modelName);
|
||||
|
||||
// Construct and return Model
|
||||
return new $className();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the classname for the given Model name.
|
||||
*
|
||||
* @param string $modelName Model name to get classname of
|
||||
* @return string Classname fore the Model name
|
||||
*/
|
||||
private static function getClassName($modelName)
|
||||
{
|
||||
$className = ClassLoader::concatClassNames($modelName, ClassLoader::stripNamespace(get_class()));
|
||||
|
||||
|
||||
return \nre\configs\AppConfig::$app['namespace']."models\\$className";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new Model.
|
||||
*
|
||||
* TODO Catch exception
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
// Load Models
|
||||
$this->loadModels();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the Models of this Model.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
*/
|
||||
private function loadModels()
|
||||
{
|
||||
// Determine Models
|
||||
$models = array();
|
||||
if(property_exists($this, 'models')) {
|
||||
$models = $this->models;
|
||||
}
|
||||
if(!is_array($models)) {
|
||||
$models = array($models);
|
||||
}
|
||||
|
||||
|
||||
// Load Models
|
||||
foreach($models as $model)
|
||||
{
|
||||
// Load class
|
||||
Model::load($model);
|
||||
|
||||
// Construct Model
|
||||
$modelName = ucfirst(strtolower($model));
|
||||
$this->$modelName = Model::factory($model);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for implementing a Model.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the class of a Model.
|
||||
*
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @param string $modelName Name of the Model to load
|
||||
*/
|
||||
public static function load($modelName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($modelName);
|
||||
|
||||
try {
|
||||
// Load class
|
||||
ClassLoader::load($className);
|
||||
|
||||
// Validate class
|
||||
ClassLoader::check($className, get_class());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||
throw new \nre\exceptions\ModelNotValidException($e->getClassName());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
throw new \nre\exceptions\ModelNotFoundException($e->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate a Model (Factory Pattern).
|
||||
*
|
||||
* @param string $modelName Name of the Model to instantiate
|
||||
*/
|
||||
public static function factory($modelName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($modelName);
|
||||
|
||||
// Construct and return Model
|
||||
return new $className();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the classname for the given Model name.
|
||||
*
|
||||
* @param string $modelName Model name to get classname of
|
||||
* @return string Classname fore the Model name
|
||||
*/
|
||||
private static function getClassName($modelName)
|
||||
{
|
||||
$className = ClassLoader::concatClassNames($modelName, ClassLoader::stripNamespace(get_class()));
|
||||
|
||||
|
||||
return \nre\configs\AppConfig::$app['namespace']."models\\$className";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new Model.
|
||||
*
|
||||
* TODO Catch exception
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
// Load Models
|
||||
$this->loadModels();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the Models of this Model.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
*/
|
||||
private function loadModels()
|
||||
{
|
||||
// Determine Models
|
||||
$models = array();
|
||||
if(property_exists($this, 'models')) {
|
||||
$models = $this->models;
|
||||
}
|
||||
if(!is_array($models)) {
|
||||
$models = array($models);
|
||||
}
|
||||
|
||||
|
||||
// Load Models
|
||||
foreach($models as $model)
|
||||
{
|
||||
// Load class
|
||||
Model::load($model);
|
||||
|
||||
// Construct Model
|
||||
$modelName = ucfirst(strtolower($model));
|
||||
$this->$modelName = Model::factory($model);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
118
core/Request.inc
118
core/Request.inc
|
@ -1,64 +1,64 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Base class to represent a request.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
/**
|
||||
* Passed parameters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $params = array();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a parameter.
|
||||
*
|
||||
* @param int $index Index of parameter
|
||||
* @param string $defaultIndex Index of default configuration value for this parameter
|
||||
* @return string Value of parameter
|
||||
*/
|
||||
public function getParam($index, $defaultIndex=null)
|
||||
{
|
||||
// Return parameter
|
||||
if(count($this->params) > $index) {
|
||||
return $this->params[$index];
|
||||
}
|
||||
|
||||
// Return default value
|
||||
return \nre\core\Config::getDefault($defaultIndex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all parameters from index on.
|
||||
*
|
||||
* @param int $offset Offset-index
|
||||
* @return array Parameter values
|
||||
*/
|
||||
public function getParams($offset=0)
|
||||
{
|
||||
return array_slice($this->params, $offset);
|
||||
}
|
||||
|
||||
}
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Base class to represent a request.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
/**
|
||||
* Passed parameters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $params = array();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a parameter.
|
||||
*
|
||||
* @param int $index Index of parameter
|
||||
* @param string $defaultIndex Index of default configuration value for this parameter
|
||||
* @return string Value of parameter
|
||||
*/
|
||||
public function getParam($index, $defaultIndex=null)
|
||||
{
|
||||
// Return parameter
|
||||
if(count($this->params) > $index) {
|
||||
return $this->params[$index];
|
||||
}
|
||||
|
||||
// Return default value
|
||||
return \nre\core\Config::getDefault($defaultIndex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all parameters from index on.
|
||||
*
|
||||
* @param int $offset Offset-index
|
||||
* @return array Parameter values
|
||||
*/
|
||||
public function getParams($offset=0)
|
||||
{
|
||||
return array_slice($this->params, $offset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,158 +1,158 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Base class to represent a response.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Response
|
||||
{
|
||||
/**
|
||||
* Applied parameters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $params = array();
|
||||
/**
|
||||
* Generated output
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $output = '';
|
||||
/**
|
||||
* Abort futher execution
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $exit = false;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add a parameter.
|
||||
*
|
||||
* @param mixed $value Value of parameter
|
||||
*/
|
||||
public function addParam($value)
|
||||
{
|
||||
$this->params[] = $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add multiple parameters.
|
||||
*
|
||||
* @param mixed $value1 Value of first parameter
|
||||
* @param mixed … Values of further parameters
|
||||
*/
|
||||
public function addParams($value1)
|
||||
{
|
||||
$this->params = array_merge(
|
||||
$this->params,
|
||||
func_get_args()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete all stored parameters (from offset on).
|
||||
*
|
||||
* @param int $offset Offset-index
|
||||
*/
|
||||
public function clearParams($offset=0)
|
||||
{
|
||||
$this->params = array_slice($this->params, 0, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a parameter.
|
||||
*
|
||||
* @param int $index Index of parameter
|
||||
* @param string $defaultIndex Index of default configuration value for this parameter
|
||||
* @return string Value of parameter
|
||||
*/
|
||||
public function getParam($index, $defaultIndex=null)
|
||||
{
|
||||
// Return parameter
|
||||
if(count($this->params) > $index) {
|
||||
return $this->params[$index];
|
||||
}
|
||||
|
||||
|
||||
// Return default value
|
||||
return \nre\core\Config::getDefault($defaultIndex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all parameters from index on.
|
||||
*
|
||||
* @param int $offset Offset-index
|
||||
* @return array Parameter values
|
||||
*/
|
||||
public function getParams($offset=0)
|
||||
{
|
||||
return array_slice($this->params, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set output.
|
||||
*
|
||||
* @param string $output Generated output
|
||||
*/
|
||||
public function setOutput($output)
|
||||
{
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get generated output.
|
||||
*
|
||||
* @return string Generated output
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set exit-state.
|
||||
*
|
||||
* @param bool $exit Abort further execution
|
||||
*/
|
||||
public function setExit($exit=true)
|
||||
{
|
||||
$this->exit = $exit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get exit-state.
|
||||
*
|
||||
* @return bool Abort further execution
|
||||
*/
|
||||
public function getExit()
|
||||
{
|
||||
return $this->exit;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Base class to represent a response.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class Response
|
||||
{
|
||||
/**
|
||||
* Applied parameters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $params = array();
|
||||
/**
|
||||
* Generated output
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $output = '';
|
||||
/**
|
||||
* Abort futher execution
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $exit = false;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add a parameter.
|
||||
*
|
||||
* @param mixed $value Value of parameter
|
||||
*/
|
||||
public function addParam($value)
|
||||
{
|
||||
$this->params[] = $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add multiple parameters.
|
||||
*
|
||||
* @param mixed $value1 Value of first parameter
|
||||
* @param mixed … Values of further parameters
|
||||
*/
|
||||
public function addParams($value1)
|
||||
{
|
||||
$this->params = array_merge(
|
||||
$this->params,
|
||||
func_get_args()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete all stored parameters (from offset on).
|
||||
*
|
||||
* @param int $offset Offset-index
|
||||
*/
|
||||
public function clearParams($offset=0)
|
||||
{
|
||||
$this->params = array_slice($this->params, 0, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a parameter.
|
||||
*
|
||||
* @param int $index Index of parameter
|
||||
* @param string $defaultIndex Index of default configuration value for this parameter
|
||||
* @return string Value of parameter
|
||||
*/
|
||||
public function getParam($index, $defaultIndex=null)
|
||||
{
|
||||
// Return parameter
|
||||
if(count($this->params) > $index) {
|
||||
return $this->params[$index];
|
||||
}
|
||||
|
||||
|
||||
// Return default value
|
||||
return \nre\core\Config::getDefault($defaultIndex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all parameters from index on.
|
||||
*
|
||||
* @param int $offset Offset-index
|
||||
* @return array Parameter values
|
||||
*/
|
||||
public function getParams($offset=0)
|
||||
{
|
||||
return array_slice($this->params, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set output.
|
||||
*
|
||||
* @param string $output Generated output
|
||||
*/
|
||||
public function setOutput($output)
|
||||
{
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get generated output.
|
||||
*
|
||||
* @return string Generated output
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set exit-state.
|
||||
*
|
||||
* @param bool $exit Abort further execution
|
||||
*/
|
||||
public function setExit($exit=true)
|
||||
{
|
||||
$this->exit = $exit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get exit-state.
|
||||
*
|
||||
* @return bool Abort further execution
|
||||
*/
|
||||
public function getExit()
|
||||
{
|
||||
return $this->exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
240
core/View.inc
240
core/View.inc
|
@ -1,124 +1,124 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* View.
|
||||
*
|
||||
* Class to encapsulate a template file and to provide rendering methods.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class View
|
||||
{
|
||||
/**
|
||||
* Template filename
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $templateFilename;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load and instantiate the View of an Agent.
|
||||
*
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @param string $layoutName Name of Layout in use
|
||||
* @param string $agentName Name of the Agent
|
||||
* @param string $action Current Action
|
||||
* @param bool $isToplevel Agent is a ToplevelAgent
|
||||
*/
|
||||
public static function loadAndFactory($layoutName, $agentName=null, $action=null, $isToplevel=false)
|
||||
{
|
||||
return new View($layoutName, $agentName, $action, $isToplevel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new View.
|
||||
*
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @param string $layoutName Name of Layout in use
|
||||
* @param string $agentName Name of the Agent
|
||||
* @param string $action Current Action
|
||||
* @param bool $isToplevel Agent is a ToplevelAgent
|
||||
*/
|
||||
protected function __construct($layoutName, $agentName=null, $action=null, $isToplevel=false)
|
||||
{
|
||||
// Create template filename
|
||||
// LayoutName
|
||||
$fileName = ROOT.DS. \nre\configs\CoreConfig::getClassDir('views').DS. strtolower($layoutName).DS;
|
||||
// AgentName and Action
|
||||
if(strtolower($agentName) != strtolower($layoutName) || !$isToplevel) {
|
||||
$fileName .= strtolower($agentName).DS.strtolower($action);
|
||||
}
|
||||
else {
|
||||
$fileName .= strtolower($layoutName);
|
||||
}
|
||||
// File extension
|
||||
$fileName .= \nre\configs\CoreConfig::getFileExt('views');
|
||||
|
||||
|
||||
// Check template file
|
||||
if(!file_exists($fileName)) {
|
||||
throw new \nre\exceptions\ViewNotFoundException($fileName);
|
||||
}
|
||||
|
||||
// Save filename
|
||||
$this->templateFilename = $fileName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate output
|
||||
*
|
||||
* @param array $data Data to have available in the template file
|
||||
*/
|
||||
public function render($data)
|
||||
{
|
||||
// Extract data
|
||||
if(!is_null($data)) {
|
||||
extract($data, EXTR_SKIP);
|
||||
}
|
||||
|
||||
// Buffer output
|
||||
ob_start();
|
||||
|
||||
// Include template
|
||||
include($this->templateFilename);
|
||||
|
||||
|
||||
// Return buffered output
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get template filename.
|
||||
*
|
||||
* @return string Template filename
|
||||
*/
|
||||
public function getTemplateFilename()
|
||||
{
|
||||
return $this->templateFilename;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* View.
|
||||
*
|
||||
* Class to encapsulate a template file and to provide rendering methods.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class View
|
||||
{
|
||||
/**
|
||||
* Template filename
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $templateFilename;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load and instantiate the View of an Agent.
|
||||
*
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @param string $layoutName Name of Layout in use
|
||||
* @param string $agentName Name of the Agent
|
||||
* @param string $action Current Action
|
||||
* @param bool $isToplevel Agent is a ToplevelAgent
|
||||
*/
|
||||
public static function loadAndFactory($layoutName, $agentName=null, $action=null, $isToplevel=false)
|
||||
{
|
||||
return new View($layoutName, $agentName, $action, $isToplevel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new View.
|
||||
*
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @param string $layoutName Name of Layout in use
|
||||
* @param string $agentName Name of the Agent
|
||||
* @param string $action Current Action
|
||||
* @param bool $isToplevel Agent is a ToplevelAgent
|
||||
*/
|
||||
protected function __construct($layoutName, $agentName=null, $action=null, $isToplevel=false)
|
||||
{
|
||||
// Create template filename
|
||||
// LayoutName
|
||||
$fileName = ROOT.DS. \nre\configs\CoreConfig::getClassDir('views').DS. strtolower($layoutName).DS;
|
||||
// AgentName and Action
|
||||
if(strtolower($agentName) != strtolower($layoutName) || !$isToplevel) {
|
||||
$fileName .= strtolower($agentName).DS.strtolower($action);
|
||||
}
|
||||
else {
|
||||
$fileName .= strtolower($layoutName);
|
||||
}
|
||||
// File extension
|
||||
$fileName .= \nre\configs\CoreConfig::getFileExt('views');
|
||||
|
||||
|
||||
// Check template file
|
||||
if(!file_exists($fileName)) {
|
||||
throw new \nre\exceptions\ViewNotFoundException($fileName);
|
||||
}
|
||||
|
||||
// Save filename
|
||||
$this->templateFilename = $fileName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate output
|
||||
*
|
||||
* @param array $data Data to have available in the template file
|
||||
*/
|
||||
public function render($data)
|
||||
{
|
||||
// Extract data
|
||||
if(!is_null($data)) {
|
||||
extract($data, EXTR_SKIP);
|
||||
}
|
||||
|
||||
// Buffer output
|
||||
ob_start();
|
||||
|
||||
// Include template
|
||||
include($this->templateFilename);
|
||||
|
||||
|
||||
// Return buffered output
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get template filename.
|
||||
*
|
||||
* @return string Template filename
|
||||
*/
|
||||
public function getTemplateFilename()
|
||||
{
|
||||
return $this->templateFilename;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,75 +1,75 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Class that holds several web-specific methods and properties.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class WebUtils
|
||||
{
|
||||
/**
|
||||
* HTTP-statuscode 403: Forbidden
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HTTP_FORBIDDEN = 403;
|
||||
/**
|
||||
* HTTP-statuscode 404: Not Found
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HTTP_NOT_FOUND = 404;
|
||||
/**
|
||||
* HTTP-statuscode 503: Service Unavailable
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HTTP_SERVICE_UNAVAILABLE = 503;
|
||||
|
||||
/**
|
||||
* HTTP-header strings
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $httpStrings = array(
|
||||
200 => 'OK',
|
||||
304 => 'Not Modified',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
503 => 'Service Unavailable'
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the HTTP-header of a HTTP-statuscode
|
||||
*
|
||||
* @param int $httpStatusCode HTTP-statuscode
|
||||
* @return string HTTP-header of HTTP-statuscode
|
||||
*/
|
||||
public static function getHttpHeader($httpStatusCode)
|
||||
{
|
||||
if(!array_key_exists($httpStatusCode, self::$httpStrings)) {
|
||||
$httpStatusCode = 200;
|
||||
}
|
||||
|
||||
|
||||
return sprintf("HTTP/1.1 %d %s\n", $httpStatusCode, self::$httpStrings[$httpStatusCode]);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\core;
|
||||
|
||||
|
||||
/**
|
||||
* Class that holds several web-specific methods and properties.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class WebUtils
|
||||
{
|
||||
/**
|
||||
* HTTP-statuscode 403: Forbidden
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HTTP_FORBIDDEN = 403;
|
||||
/**
|
||||
* HTTP-statuscode 404: Not Found
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HTTP_NOT_FOUND = 404;
|
||||
/**
|
||||
* HTTP-statuscode 503: Service Unavailable
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HTTP_SERVICE_UNAVAILABLE = 503;
|
||||
|
||||
/**
|
||||
* HTTP-header strings
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $httpStrings = array(
|
||||
200 => 'OK',
|
||||
304 => 'Not Modified',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
503 => 'Service Unavailable'
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the HTTP-header of a HTTP-statuscode
|
||||
*
|
||||
* @param int $httpStatusCode HTTP-statuscode
|
||||
* @return string HTTP-header of HTTP-statuscode
|
||||
*/
|
||||
public static function getHttpHeader($httpStatusCode)
|
||||
{
|
||||
if(!array_key_exists($httpStatusCode, self::$httpStrings)) {
|
||||
$httpStatusCode = 200;
|
||||
}
|
||||
|
||||
|
||||
return sprintf("HTTP/1.1 %d %s\n", $httpStatusCode, self::$httpStrings[$httpStatusCode]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,87 +1,87 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\drivers;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for implementing a database driver.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class DatabaseDriver extends \nre\core\Driver
|
||||
{
|
||||
/**
|
||||
* Driver class instance
|
||||
*
|
||||
* @static
|
||||
* @var DatabaseDriver
|
||||
*/
|
||||
protected static $driver = null;
|
||||
/**
|
||||
* Connection resource
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $connection = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Singleton-pattern.
|
||||
*
|
||||
* @param array $config Database driver configuration
|
||||
* @return DatabaseDriver Singleton-instance of database driver class
|
||||
*/
|
||||
public static function singleton($config)
|
||||
{
|
||||
// Singleton
|
||||
if(self::$driver !== null) {
|
||||
return self::$driver;
|
||||
}
|
||||
|
||||
// Construct
|
||||
$className = get_called_class();
|
||||
self::$driver = new $className($config);
|
||||
|
||||
|
||||
return self::$driver;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new database driver.
|
||||
*
|
||||
* @param array $config Connection and login settings
|
||||
*/
|
||||
protected function __construct($config)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Establish connection
|
||||
$this->connect($config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Establish a connect to a MqSQL-database.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param array $config Connection and login settings
|
||||
*/
|
||||
protected abstract function connect($config);
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\drivers;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class for implementing a database driver.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
abstract class DatabaseDriver extends \nre\core\Driver
|
||||
{
|
||||
/**
|
||||
* Driver class instance
|
||||
*
|
||||
* @static
|
||||
* @var DatabaseDriver
|
||||
*/
|
||||
protected static $driver = null;
|
||||
/**
|
||||
* Connection resource
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $connection = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Singleton-pattern.
|
||||
*
|
||||
* @param array $config Database driver configuration
|
||||
* @return DatabaseDriver Singleton-instance of database driver class
|
||||
*/
|
||||
public static function singleton($config)
|
||||
{
|
||||
// Singleton
|
||||
if(self::$driver !== null) {
|
||||
return self::$driver;
|
||||
}
|
||||
|
||||
// Construct
|
||||
$className = get_called_class();
|
||||
self::$driver = new $className($config);
|
||||
|
||||
|
||||
return self::$driver;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new database driver.
|
||||
*
|
||||
* @param array $config Connection and login settings
|
||||
*/
|
||||
protected function __construct($config)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Establish connection
|
||||
$this->connect($config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Establish a connect to a MqSQL-database.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param array $config Connection and login settings
|
||||
*/
|
||||
protected abstract function connect($config);
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,167 +1,167 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\drivers;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of a database driver for MySQL-databases.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class MysqliDriver extends \nre\drivers\DatabaseDriver
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a MySQL-driver.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param array $config Connection and login settings
|
||||
*/
|
||||
function __construct($config)
|
||||
{
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Execute a SQL-query.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param string $query Query to run
|
||||
* @param mixed … Params
|
||||
* @return array Result
|
||||
*/
|
||||
public function query($query)
|
||||
{
|
||||
// Prepare statement
|
||||
if(!($stmt = $this->connection->prepare($query))) {
|
||||
throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno);
|
||||
}
|
||||
|
||||
try {
|
||||
// Prepare data
|
||||
$data = array();
|
||||
|
||||
// Bind parameters
|
||||
$p = array_slice(func_get_args(), 1);
|
||||
$params = array();
|
||||
foreach($p as $key => $value) {
|
||||
$params[$key] = &$p[$key];
|
||||
}
|
||||
if(count($params) > 0)
|
||||
{
|
||||
if(!(call_user_func_array(array($stmt, 'bind_param'), $params))) {
|
||||
throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno);
|
||||
}
|
||||
}
|
||||
|
||||
// Execute query
|
||||
if(!$stmt->execute()) {
|
||||
throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno);
|
||||
}
|
||||
|
||||
// Fetch result
|
||||
if($result = $stmt->get_result()) {
|
||||
while($row = $result->fetch_assoc()) {
|
||||
$data[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
finally {
|
||||
$stmt->close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the last insert id (of the last insert-query).
|
||||
*
|
||||
* @return int Last insert id
|
||||
*/
|
||||
public function getInsertId()
|
||||
{
|
||||
return $this->connection->insert_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enable/disable autocommit feature.
|
||||
*
|
||||
* @param boolean $autocommit Enable/disable autocommit
|
||||
*/
|
||||
public function setAutocommit($autocommit)
|
||||
{
|
||||
$this->connection->autocommit($autocommit);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rollback the current transaction.
|
||||
*/
|
||||
public function rollback()
|
||||
{
|
||||
$this->connection->rollback();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
*/
|
||||
public function commit()
|
||||
{
|
||||
$this->connection->commit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Establish a connect to a MqSQL-database.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param array $config Connection and login settings
|
||||
*/
|
||||
protected function connect($config)
|
||||
{
|
||||
// Connect
|
||||
$con = @new \mysqli(
|
||||
$config['host'],
|
||||
$config['user'],
|
||||
$config['password'],
|
||||
$config['db']
|
||||
);
|
||||
|
||||
// Check connection
|
||||
if($con->connect_error) {
|
||||
throw new \nre\exceptions\DatamodelException($con->connect_error, $con->connect_errno);
|
||||
}
|
||||
|
||||
// Set character encoding
|
||||
if(!$con->set_charset('utf8')) {
|
||||
throw new \nre\exceptions\DatamodelException($con->connect_error, $con->connect_errno);
|
||||
}
|
||||
|
||||
// Save connection
|
||||
$this->connection = $con;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\drivers;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of a database driver for MySQL-databases.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class MysqliDriver extends \nre\drivers\DatabaseDriver
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a MySQL-driver.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param array $config Connection and login settings
|
||||
*/
|
||||
function __construct($config)
|
||||
{
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Execute a SQL-query.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param string $query Query to run
|
||||
* @param mixed … Params
|
||||
* @return array Result
|
||||
*/
|
||||
public function query($query)
|
||||
{
|
||||
// Prepare statement
|
||||
if(!($stmt = $this->connection->prepare($query))) {
|
||||
throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno);
|
||||
}
|
||||
|
||||
try {
|
||||
// Prepare data
|
||||
$data = array();
|
||||
|
||||
// Bind parameters
|
||||
$p = array_slice(func_get_args(), 1);
|
||||
$params = array();
|
||||
foreach($p as $key => $value) {
|
||||
$params[$key] = &$p[$key];
|
||||
}
|
||||
if(count($params) > 0)
|
||||
{
|
||||
if(!(call_user_func_array(array($stmt, 'bind_param'), $params))) {
|
||||
throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno);
|
||||
}
|
||||
}
|
||||
|
||||
// Execute query
|
||||
if(!$stmt->execute()) {
|
||||
throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno);
|
||||
}
|
||||
|
||||
// Fetch result
|
||||
if($result = $stmt->get_result()) {
|
||||
while($row = $result->fetch_assoc()) {
|
||||
$data[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
finally {
|
||||
$stmt->close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the last insert id (of the last insert-query).
|
||||
*
|
||||
* @return int Last insert id
|
||||
*/
|
||||
public function getInsertId()
|
||||
{
|
||||
return $this->connection->insert_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enable/disable autocommit feature.
|
||||
*
|
||||
* @param boolean $autocommit Enable/disable autocommit
|
||||
*/
|
||||
public function setAutocommit($autocommit)
|
||||
{
|
||||
$this->connection->autocommit($autocommit);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rollback the current transaction.
|
||||
*/
|
||||
public function rollback()
|
||||
{
|
||||
$this->connection->rollback();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Commit the current transaction.
|
||||
*/
|
||||
public function commit()
|
||||
{
|
||||
$this->connection->commit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Establish a connect to a MqSQL-database.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @param array $config Connection and login settings
|
||||
*/
|
||||
protected function connect($config)
|
||||
{
|
||||
// Connect
|
||||
$con = @new \mysqli(
|
||||
$config['host'],
|
||||
$config['user'],
|
||||
$config['password'],
|
||||
$config['db']
|
||||
);
|
||||
|
||||
// Check connection
|
||||
if($con->connect_error) {
|
||||
throw new \nre\exceptions\DatamodelException($con->connect_error, $con->connect_errno);
|
||||
}
|
||||
|
||||
// Set character encoding
|
||||
if(!$con->set_charset('utf8')) {
|
||||
throw new \nre\exceptions\DatamodelException($con->connect_error, $con->connect_errno);
|
||||
}
|
||||
|
||||
// Save connection
|
||||
$this->connection = $con;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,51 +1,51 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Access denied.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class AccessDeniedException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 85;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'access denied';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Consturct a new exception.
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
self::MESSAGE,
|
||||
self::CODE
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Access denied.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class AccessDeniedException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 85;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'access denied';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Consturct a new exception.
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
self::MESSAGE,
|
||||
self::CODE
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,77 +1,77 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Action not found.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ActionNotFoundException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 70;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'action not found';
|
||||
|
||||
/**
|
||||
* Name of the action that was not found
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $action;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $action Name of the action that was not found
|
||||
*/
|
||||
function __construct($action)
|
||||
{
|
||||
parent::__construct(
|
||||
self::MESSAGE,
|
||||
self::CODE,
|
||||
$action
|
||||
);
|
||||
|
||||
// Store values
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the action that was not found.
|
||||
*
|
||||
* @return string Name of the action that was not found
|
||||
*/
|
||||
public function getAction()
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Action not found.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ActionNotFoundException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 70;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'action not found';
|
||||
|
||||
/**
|
||||
* Name of the action that was not found
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $action;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $action Name of the action that was not found
|
||||
*/
|
||||
function __construct($action)
|
||||
{
|
||||
parent::__construct(
|
||||
self::MESSAGE,
|
||||
self::CODE,
|
||||
$action
|
||||
);
|
||||
|
||||
// Store values
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the action that was not found.
|
||||
*
|
||||
* @return string Name of the action that was not found
|
||||
*/
|
||||
public function getAction()
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,67 +1,67 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Agent not found.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class AgentNotFoundException extends \nre\exceptions\ClassNotFoundException
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 66;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'agent not found';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $agentName Name of the Agent that was not found
|
||||
*/
|
||||
function __construct($agentName)
|
||||
{
|
||||
parent::__construct(
|
||||
$agentName,
|
||||
self::MESSAGE,
|
||||
self::CODE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the Agent that was not found.
|
||||
*
|
||||
* @return string Name of the Agent that was not found
|
||||
*/
|
||||
public function getAgentName()
|
||||
{
|
||||
return $this->getClassName();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Agent not found.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class AgentNotFoundException extends \nre\exceptions\ClassNotFoundException
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 66;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'agent not found';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $agentName Name of the Agent that was not found
|
||||
*/
|
||||
function __construct($agentName)
|
||||
{
|
||||
parent::__construct(
|
||||
$agentName,
|
||||
self::MESSAGE,
|
||||
self::CODE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the Agent that was not found.
|
||||
*
|
||||
* @return string Name of the Agent that was not found
|
||||
*/
|
||||
public function getAgentName()
|
||||
{
|
||||
return $this->getClassName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,67 +1,67 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Agent not valid.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class AgentNotValidException extends \nre\exceptions\ClassNotValidException
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 76;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'agent not valid';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $agentName Name of the invalid Agent
|
||||
*/
|
||||
function __construct($agentName)
|
||||
{
|
||||
parent::__construct(
|
||||
$agentName,
|
||||
self::MESSAGE,
|
||||
self::CODE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the invalid Agent.
|
||||
*
|
||||
* @return string Name of the invalid Agent
|
||||
*/
|
||||
public function getAgentName()
|
||||
{
|
||||
return $this->getClassName();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Agent not valid.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class AgentNotValidException extends \nre\exceptions\ClassNotValidException
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 76;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'agent not valid';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $agentName Name of the invalid Agent
|
||||
*/
|
||||
function __construct($agentName)
|
||||
{
|
||||
parent::__construct(
|
||||
$agentName,
|
||||
self::MESSAGE,
|
||||
self::CODE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the invalid Agent.
|
||||
*
|
||||
* @return string Name of the invalid Agent
|
||||
*/
|
||||
public function getAgentName()
|
||||
{
|
||||
return $this->getClassName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,79 +1,79 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Class not found.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ClassNotFoundException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 64;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'class not found';
|
||||
|
||||
/**
|
||||
* Name of the class that was not found
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $className;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception
|
||||
*
|
||||
* @param string $className Name of the class that was not found
|
||||
* @param string $message Error message (superclass)
|
||||
* @param int $code Error code (superclass)
|
||||
*/
|
||||
function __construct($className, $message=self::MESSAGE, $code=self::CODE)
|
||||
{
|
||||
parent::__construct(
|
||||
$message,
|
||||
$code,
|
||||
$className
|
||||
);
|
||||
|
||||
// Store values
|
||||
$this->className = $className;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the class that was not found.
|
||||
*
|
||||
* @return string Name of the class that was not found
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->className;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Class not found.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ClassNotFoundException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 64;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'class not found';
|
||||
|
||||
/**
|
||||
* Name of the class that was not found
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $className;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception
|
||||
*
|
||||
* @param string $className Name of the class that was not found
|
||||
* @param string $message Error message (superclass)
|
||||
* @param int $code Error code (superclass)
|
||||
*/
|
||||
function __construct($className, $message=self::MESSAGE, $code=self::CODE)
|
||||
{
|
||||
parent::__construct(
|
||||
$message,
|
||||
$code,
|
||||
$className
|
||||
);
|
||||
|
||||
// Store values
|
||||
$this->className = $className;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the class that was not found.
|
||||
*
|
||||
* @return string Name of the class that was not found
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->className;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,79 +1,79 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Class not valid.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ClassNotValidException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 74;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'class not valid';
|
||||
|
||||
/**
|
||||
* Name of the invalid class
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $className;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $className Name of the invalid class
|
||||
* @param string $message Error message (superclass)
|
||||
* @param int $code Error code (superclass)
|
||||
*/
|
||||
function __construct($className, $message=self::MESSAGE, $code=self::CODE)
|
||||
{
|
||||
parent::__construct(
|
||||
$message,
|
||||
$code,
|
||||
$className
|
||||
);
|
||||
|
||||
// Store value
|
||||
$this->className = $className;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the invalid class.
|
||||
*
|
||||
* @return string Name of the invalid class
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->className;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Class not valid.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ClassNotValidException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 74;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'class not valid';
|
||||
|
||||
/**
|
||||
* Name of the invalid class
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $className;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $className Name of the invalid class
|
||||
* @param string $message Error message (superclass)
|
||||
* @param int $code Error code (superclass)
|
||||
*/
|
||||
function __construct($className, $message=self::MESSAGE, $code=self::CODE)
|
||||
{
|
||||
parent::__construct(
|
||||
$message,
|
||||
$code,
|
||||
$className
|
||||
);
|
||||
|
||||
// Store value
|
||||
$this->className = $className;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the invalid class.
|
||||
*
|
||||
* @return string Name of the invalid class
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->className;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,67 +1,67 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Component not found.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ComponentNotFoundException extends \nre\exceptions\ClassNotFoundException
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 67;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'component not found';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $componentName Name of the Component that was not found
|
||||
*/
|
||||
function __construct($componentName)
|
||||
{
|
||||
parent::__construct(
|
||||
$componentName,
|
||||
self::MESSAGE,
|
||||
self::CODE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the Component that was not found.
|
||||
*
|
||||
* @return string Name of the Component that was not found
|
||||
*/
|
||||
public function getComponentName()
|
||||
{
|
||||
return $this->getClassName();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Component not found.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ComponentNotFoundException extends \nre\exceptions\ClassNotFoundException
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 67;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'component not found';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $componentName Name of the Component that was not found
|
||||
*/
|
||||
function __construct($componentName)
|
||||
{
|
||||
parent::__construct(
|
||||
$componentName,
|
||||
self::MESSAGE,
|
||||
self::CODE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the Component that was not found.
|
||||
*
|
||||
* @return string Name of the Component that was not found
|
||||
*/
|
||||
public function getComponentName()
|
||||
{
|
||||
return $this->getClassName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,67 +1,67 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Component not valid.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ComponentNotValidException extends \nre\exceptions\ClassNotValidException
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 77;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'component not valid';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $componentName Name of the invalid Component
|
||||
*/
|
||||
function __construct($componentName)
|
||||
{
|
||||
parent::__construct(
|
||||
$componentName,
|
||||
self::MESSAGE,
|
||||
self::CODE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the invalid Component.
|
||||
*
|
||||
* @return string Name of the invalid Component
|
||||
*/
|
||||
public function getComponentName()
|
||||
{
|
||||
return $this->getClassName();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Component not valid.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ComponentNotValidException extends \nre\exceptions\ClassNotValidException
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 77;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'component not valid';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $componentName Name of the invalid Component
|
||||
*/
|
||||
function __construct($componentName)
|
||||
{
|
||||
parent::__construct(
|
||||
$componentName,
|
||||
self::MESSAGE,
|
||||
self::CODE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the invalid Component.
|
||||
*
|
||||
* @return string Name of the invalid Component
|
||||
*/
|
||||
public function getComponentName()
|
||||
{
|
||||
return $this->getClassName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,67 +1,67 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: Controller not found.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class ControllerNotFoundException extends \nre\exceptions\ClassNotFoundException
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 67;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'controller not found';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $controllerName Name of the Controller that was not found
|
||||
*/
|
||||
function __construct($controllerName)
|
||||
{
|
||||
parent::__construct(
|
||||
$controllerName,
|
||||
self::MESSAGE,
|
||||
self::CODE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||