replace tabs with spaces

This commit is contained in:
coderkun 2015-04-25 16:22:31 +02:00
commit 2a7ed82695
53 changed files with 6198 additions and 6198 deletions

View file

@ -1,25 +1,25 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\agents; namespace nre\agents;
/** /**
* The BottomlevelAgent is the standard Agent and can have indefinite * The BottomlevelAgent is the standard Agent and can have indefinite
* SubAgents. * SubAgents.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
abstract class BottomlevelAgent extends \nre\core\Agent abstract class BottomlevelAgent extends \nre\core\Agent
{ {
} }
?> ?>

View file

@ -1,49 +1,49 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\agents; namespace nre\agents;
/** /**
* The IntermediateAgent assumes the task of a module. There is only one * The IntermediateAgent assumes the task of a module. There is only one
* IntermediateAgent per request. * IntermediateAgent per request.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
abstract class IntermediateAgent extends \nre\core\Agent abstract class IntermediateAgent extends \nre\core\Agent
{ {
/** /**
* Get the layout if it was explicitly defined. * Get the layout if it was explicitly defined.
* *
* @param string $agentName Agent name * @param string $agentName Agent name
* @return string Layout of the IntermediateAgent * @return string Layout of the IntermediateAgent
*/ */
public static function getLayout($agentName) public static function getLayout($agentName)
{ {
// Determine classname // Determine classname
$className = Autoloader::concatClassNames($agentName, 'Agent'); $className = Autoloader::concatClassNames($agentName, 'Agent');
// Check property // Check property
if(isset($className::$layout)) { if(isset($className::$layout)) {
return $className::$layout; return $className::$layout;
} }
return null; return null;
} }
} }
?> ?>

View file

@ -1,395 +1,395 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\agents; namespace nre\agents;
/** /**
* The ToplevelAgent assumes the task of a FrontController. There is * The ToplevelAgent assumes the task of a FrontController. There is
* only one per request. * only one per request.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ToplevelAgent extends \nre\core\Agent class ToplevelAgent extends \nre\core\Agent
{ {
/** /**
* Stage: Load * Stage: Load
* *
* @var string * @var string
*/ */
const STAGE_LOAD = 'load'; const STAGE_LOAD = 'load';
/** /**
* Stage: Run * Stage: Run
* *
* @var string * @var string
*/ */
const STAGE_RUN = 'run'; const STAGE_RUN = 'run';
/** /**
* Current request * Current request
* *
* @var \nre\core\Request * @var \nre\core\Request
*/ */
private $request; private $request;
/** /**
* Current response * Current response
* *
* @var \nre\core\Response * @var \nre\core\Response
*/ */
private $response; private $response;
/** /**
* Layout instace * Layout instace
* *
* @var \nre\core\Layout * @var \nre\core\Layout
*/ */
private $layout = null; private $layout = null;
/** /**
* IntermediateAgent instance * IntermediateAgent instance
* *
* @var IntermediateAgent * @var IntermediateAgent
*/ */
private $intermediateAgent = null; private $intermediateAgent = null;
/** /**
* Construct a ToplevelAgent. * Construct a ToplevelAgent.
* *
* @throws \nre\exceptions\ServiceUnavailableException * @throws \nre\exceptions\ServiceUnavailableException
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @throws \nre\exceptions\DriverNotValidException * @throws \nre\exceptions\DriverNotValidException
* @throws \nre\exceptions\DriverNotFoundException * @throws \nre\exceptions\DriverNotFoundException
* @throws \nre\exceptions\ViewNotFoundException * @throws \nre\exceptions\ViewNotFoundException
* @throws \nre\exceptions\ModelNotValidException * @throws \nre\exceptions\ModelNotValidException
* @throws \nre\exceptions\ModelNotFoundException * @throws \nre\exceptions\ModelNotFoundException
* @throws \nre\exceptions\ControllerNotValidException * @throws \nre\exceptions\ControllerNotValidException
* @throws \nre\exceptions\ControllerNotFoundException * @throws \nre\exceptions\ControllerNotFoundException
* @param \nre\core\Request $request Current request * @param \nre\core\Request $request Current request
* @param \nre\core\Response $response Current response * @param \nre\core\Response $response Current response
* @param \nre\core\Logger $log Log-system * @param \nre\core\Logger $log Log-system
*/ */
protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null) protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
{ {
// Store values // Store values
$this->request = $request; $this->request = $request;
$this->response = $response; $this->response = $response;
// Create response // Create response
$response = clone $response; $response = clone $response;
$response->clearParams(1); $response->clearParams(1);
$response->addParams( $response->addParams(
null, null,
\nre\configs\CoreConfig::$defaults['action'] \nre\configs\CoreConfig::$defaults['action']
); );
// Call parent constructor // Call parent constructor
parent::__construct($request, $response, $log, true); parent::__construct($request, $response, $log, true);
// Load IntermediateAgent // Load IntermediateAgent
$this->loadIntermediateAgent(); $this->loadIntermediateAgent();
} }
/** /**
* Run the Controller of this Agent and its SubAgents. * Run the Controller of this Agent and its SubAgents.
* *
* @throws \nre\exceptions\ServiceUnavailableException * @throws \nre\exceptions\ServiceUnavailableException
* @param \nre\core\Request $request Current request * @param \nre\core\Request $request Current request
* @param \nre\core\Response $response Current response * @param \nre\core\Response $response Current response
* @return \Exception Last occurred exception of SubAgents * @return \Exception Last occurred exception of SubAgents
*/ */
public function run(\nre\core\Request $request, \nre\core\Response $response) public function run(\nre\core\Request $request, \nre\core\Response $response)
{ {
try { try {
return $this->_run($request, $response); return $this->_run($request, $response);
} }
catch(\nre\exceptions\AccessDeniedException $e) { catch(\nre\exceptions\AccessDeniedException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_FORBIDDEN, self::STAGE_RUN); $this->error($e, \nre\core\WebUtils::HTTP_FORBIDDEN, self::STAGE_RUN);
} }
catch(\nre\exceptions\ParamsNotValidException $e) { catch(\nre\exceptions\ParamsNotValidException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN); $this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN);
} }
catch(\nre\exceptions\IdNotFoundException $e) { catch(\nre\exceptions\IdNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN); $this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN);
} }
catch(\nre\exceptions\DatamodelException $e) { catch(\nre\exceptions\DatamodelException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE, self::STAGE_RUN); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE, self::STAGE_RUN);
} }
catch(\nre\exceptions\ActionNotFoundException $e) { catch(\nre\exceptions\ActionNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN); $this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND, self::STAGE_RUN);
} }
} }
/** /**
* Generate output of the Controller of this Agent and its * Generate output of the Controller of this Agent and its
* SubAgents. * SubAgents.
* *
* @param array $data View data * @param array $data View data
* @return string Generated output * @return string Generated output
*/ */
public function render($data=array()) public function render($data=array())
{ {
// Render IntermediateAgent // Render IntermediateAgent
$data = array(); $data = array();
$data['intermediate'] = $this->intermediateAgent->render(); $data['intermediate'] = $this->intermediateAgent->render();
// Render ToplevelAgent // Render ToplevelAgent
return parent::render($data); return parent::render($data);
} }
/** /**
* Return the IntermediateAgent. * Return the IntermediateAgent.
* *
* @return \nre\agents\IntermediateAgent IntermediateAgent * @return \nre\agents\IntermediateAgent IntermediateAgent
*/ */
public function getIntermediateAgent() public function getIntermediateAgent()
{ {
return $this->intermediateAgent; return $this->intermediateAgent;
} }
/** /**
* Load a SubAgent and add it. * Load a SubAgent and add it.
* *
* @throws \nre\exceptions\ServiceUnavailableException * @throws \nre\exceptions\ServiceUnavailableException
* @throws \nre\exceptions\FatalDatamodelException * @throws \nre\exceptions\FatalDatamodelException
* @throws \nre\exceptions\AgentNotFoundException * @throws \nre\exceptions\AgentNotFoundException
* @throws \nre\exceptions\AgentNotValidException * @throws \nre\exceptions\AgentNotValidException
* @param string $agentName Name of the Agent to load * @param string $agentName Name of the Agent to load
* @param mixed Additional parameters for the agent * @param mixed Additional parameters for the agent
*/ */
protected function addSubAgent($agentName) protected function addSubAgent($agentName)
{ {
try { try {
call_user_func_array( call_user_func_array(
array( array(
$this, $this,
'_addSubAgent' '_addSubAgent'
), ),
func_get_args() func_get_args()
); );
} }
catch(\nre\exceptions\DatamodelException $e) { catch(\nre\exceptions\DatamodelException $e) {
throw new \nre\exceptions\FatalDatamodelException($e->getDatamodelMessage(), $e->getDatamodelErrorNumber()); throw new \nre\exceptions\FatalDatamodelException($e->getDatamodelMessage(), $e->getDatamodelErrorNumber());
} }
} }
/** /**
* Load IntermediateAgent defined by the current request. * Load IntermediateAgent defined by the current request.
* *
* @throws \nre\exceptions\ServiceUnavailableException * @throws \nre\exceptions\ServiceUnavailableException
*/ */
private function loadIntermediateAgent() private function loadIntermediateAgent()
{ {
try { try {
$this->_loadIntermediateAgent(); $this->_loadIntermediateAgent();
} }
catch(\nre\exceptions\ViewNotFoundException $e) { catch(\nre\exceptions\ViewNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND); $this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
} }
catch(\nre\exceptions\DatamodelException $e) { catch(\nre\exceptions\DatamodelException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\DriverNotValidException $e) { catch(\nre\exceptions\DriverNotValidException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\DriverNotFoundException $e) { catch(\nre\exceptions\DriverNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\ModelNotValidException $e) { catch(\nre\exceptions\ModelNotValidException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\ModelNotFoundException $e) { catch(\nre\exceptions\ModelNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\ControllerNotValidException $e) { catch(\nre\exceptions\ControllerNotValidException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\ControllerNotFoundException $e) { catch(\nre\exceptions\ControllerNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND); $this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
} }
catch(\nre\exceptions\AgentNotValidException $e) { catch(\nre\exceptions\AgentNotValidException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\AgentNotFoundException $e) { catch(\nre\exceptions\AgentNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND); $this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
} }
} }
/** /**
* Load IntermediateAgent defined by the current request. * Load IntermediateAgent defined by the current request.
* *
* @throws \nre\exceptions\ServiceUnavailableException * @throws \nre\exceptions\ServiceUnavailableException
*/ */
private function _loadIntermediateAgent() private function _loadIntermediateAgent()
{ {
// Determine IntermediateAgent // Determine IntermediateAgent
$agentName = $this->response->getParam(1); $agentName = $this->response->getParam(1);
if(is_null($agentName)) { if(is_null($agentName)) {
$agentName = $this->request->getParam(1, 'intermediate'); $agentName = $this->request->getParam(1, 'intermediate');
$this->response->addParam($agentName); $this->response->addParam($agentName);
} }
// Load IntermediateAgent // Load IntermediateAgent
IntermediateAgent::load($agentName); IntermediateAgent::load($agentName);
// Determine Action // Determine Action
$action = $this->response->getParam(2); $action = $this->response->getParam(2);
if(is_null($action)) { if(is_null($action)) {
$action = $this->request->getParam(2, 'action'); $action = $this->request->getParam(2, 'action');
$this->response->addParam($action); $this->response->addParam($action);
} }
// Construct IntermediateAgent // Construct IntermediateAgent
$this->intermediateAgent = \nre\agents\IntermediateAgent::factory( $this->intermediateAgent = \nre\agents\IntermediateAgent::factory(
$agentName, $agentName,
$this->request, $this->request,
$this->response, $this->response,
$this->log $this->log
); );
} }
/** /**
* Run the Controller of this Agent and its SubAgents. * Run the Controller of this Agent and its SubAgents.
* *
* @throws \nre\exceptions\AccessDeniedException * @throws \nre\exceptions\AccessDeniedException
* @throws \nre\exceptions\IdNotFoundException * @throws \nre\exceptions\IdNotFoundException
* @throws \nre\exceptions\ServiceUnavailableException * @throws \nre\exceptions\ServiceUnavailableException
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @param \nre\core\Request $request Current request * @param \nre\core\Request $request Current request
* @param \nre\core\Response $response Current response * @param \nre\core\Response $response Current response
* @return \Exception Last occurred exception of SubAgents * @return \Exception Last occurred exception of SubAgents
*/ */
private function _run(\nre\core\Request $request, \nre\core\Response $response) private function _run(\nre\core\Request $request, \nre\core\Response $response)
{ {
// Run IntermediateAgent // Run IntermediateAgent
$this->runIntermediateAgent(); $this->runIntermediateAgent();
// TODO Request instead of response? // TODO Request instead of response?
$response = clone $response; $response = clone $response;
$response->clearParams(2); $response->clearParams(2);
$response->addParam(\nre\configs\CoreConfig::$defaults['action']); $response->addParam(\nre\configs\CoreConfig::$defaults['action']);
// Run ToplevelAgent // Run ToplevelAgent
return parent::run($request, $response); return parent::run($request, $response);
} }
/** /**
* Run IntermediateAgent. * Run IntermediateAgent.
* *
* @throws \nre\exceptions\AccessDeniedException * @throws \nre\exceptions\AccessDeniedException
* @throws \nre\exceptions\ParamsNotValidException * @throws \nre\exceptions\ParamsNotValidException
* @throws \nre\exceptions\IdNotFoundException * @throws \nre\exceptions\IdNotFoundException
* @throws \nre\exceptions\ServiceUnavailableException * @throws \nre\exceptions\ServiceUnavailableException
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
*/ */
private function runIntermediateAgent() private function runIntermediateAgent()
{ {
$this->intermediateAgent->run( $this->intermediateAgent->run(
$this->request, $this->request,
$this->response $this->response
); );
} }
/** /**
* Handle an error that occurred during * Handle an error that occurred during
* loading/cnostructing/running of the IntermediateAgent. * loading/cnostructing/running of the IntermediateAgent.
* *
* @throws \nre\exceptions\ServiceUnavailableException * @throws \nre\exceptions\ServiceUnavailableException
* @param \Exception $exception Occurred exception * @param \Exception $exception Occurred exception
* @param int $httpStatusCode HTTP-statuscode * @param int $httpStatusCode HTTP-statuscode
* @param string $stage Stage of execution * @param string $stage Stage of execution
*/ */
private function error($exception, $httpStatusCode, $stage=self::STAGE_LOAD) private function error($exception, $httpStatusCode, $stage=self::STAGE_LOAD)
{ {
// Log error // Log error
$this->log($exception, \nre\core\Logger::LOGMODE_AUTO); $this->log($exception, \nre\core\Logger::LOGMODE_AUTO);
try { try {
// Define ErrorAgent // Define ErrorAgent
$this->response->clearParams(1); $this->response->clearParams(1);
$this->response->addParams( $this->response->addParams(
\nre\configs\AppConfig::$defaults['intermediate-error'], \nre\configs\AppConfig::$defaults['intermediate-error'],
\nre\configs\CoreConfig::$defaults['action'], \nre\configs\CoreConfig::$defaults['action'],
$httpStatusCode $httpStatusCode
); );
// Load ErrorAgent // Load ErrorAgent
$this->_loadIntermediateAgent(); $this->_loadIntermediateAgent();
// Run ErrorAgent // Run ErrorAgent
if($stage == self::STAGE_RUN) { if($stage == self::STAGE_RUN) {
$this->_run($this->request, $this->response); $this->_run($this->request, $this->response);
} }
} }
catch(\nre\exceptions\ActionNotFoundException $e) { catch(\nre\exceptions\ActionNotFoundException $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
catch(\nre\exceptions\DatamodelException $e) { catch(\nre\exceptions\DatamodelException $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
catch(\nre\exceptions\DriverNotValidException $e) { catch(\nre\exceptions\DriverNotValidException $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
catch(\nre\exceptions\DriverNotFoundException $e) { catch(\nre\exceptions\DriverNotFoundException $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
catch(\nre\exceptions\ModelNotValidException $e) { catch(\nre\exceptions\ModelNotValidException $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
catch(\nre\exceptions\ModelNotFoundException $e) { catch(\nre\exceptions\ModelNotFoundException $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
catch(\nre\exceptions\ViewNotFoundException $e) { catch(\nre\exceptions\ViewNotFoundException $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
catch(\nre\exceptions\ControllerNotValidException $e) { catch(\nre\exceptions\ControllerNotValidException $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
catch(\nre\exceptions\ControllerNotFoundException $e) { catch(\nre\exceptions\ControllerNotFoundException $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
catch(\nre\exceptions\AgentNotValidException $e) { catch(\nre\exceptions\AgentNotValidException $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
catch(\nre\exceptions\AgentNotFoundException $e) { catch(\nre\exceptions\AgentNotFoundException $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
catch(Exception $e) { catch(Exception $e) {
throw new \nre\exceptions\ServiceUnavailableException($e); throw new \nre\exceptions\ServiceUnavailableException($e);
} }
} }
} }
?> ?>

View file

@ -1,250 +1,250 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\apis; namespace nre\apis;
/** /**
* WebApi-implementation. * WebApi-implementation.
* *
* This class runs and renders an web-applictaion. * This class runs and renders an web-applictaion.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class WebApi extends \nre\core\Api class WebApi extends \nre\core\Api
{ {
/** /**
* Construct a new WebApi. * Construct a new WebApi.
*/ */
public function __construct() public function __construct()
{ {
parent::__construct( parent::__construct(
new \nre\requests\WebRequest(), new \nre\requests\WebRequest(),
new \nre\responses\WebResponse() new \nre\responses\WebResponse()
); );
// Add routes // Add routes
$this->addRoutes(); $this->addRoutes();
// Disable screen logging for AJAX requests // Disable screen logging for AJAX requests
if($this->request->getParam(0, 'toplevel') == 'ajax') { if($this->request->getParam(0, 'toplevel') == 'ajax') {
$this->log->disableAutoLogToScreen(); $this->log->disableAutoLogToScreen();
} }
} }
/** /**
* Run application. * Run application.
* *
* This method runs the application and handles all errors. * This method runs the application and handles all errors.
*/ */
public function run() public function run()
{ {
try { try {
$exception = parent::run(); $exception = parent::run();
if(!is_null($exception)) { if(!is_null($exception)) {
$this->errorService($exception); $this->errorService($exception);
} }
} }
catch(\nre\exceptions\ServiceUnavailableException $e) { catch(\nre\exceptions\ServiceUnavailableException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\ActionNotFoundException $e) { catch(\nre\exceptions\ActionNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND); $this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
} }
catch(\nre\exceptions\FatalDatamodelException $e) { catch(\nre\exceptions\FatalDatamodelException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\DatamodelException $e) { catch(\nre\exceptions\DatamodelException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\DriverNotValidException $e) { catch(\nre\exceptions\DriverNotValidException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\DriverNotFoundException $e) { catch(\nre\exceptions\DriverNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\ModelNotValidException $e) { catch(\nre\exceptions\ModelNotValidException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\ModelNotFoundException $e) { catch(\nre\exceptions\ModelNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\ViewNotFoundException $e) { catch(\nre\exceptions\ViewNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND); $this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
} }
catch(\nre\exceptions\ControllerNotValidException $e) { catch(\nre\exceptions\ControllerNotValidException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\ControllerNotFoundException $e) { catch(\nre\exceptions\ControllerNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND); $this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
} }
catch(\nre\exceptions\AgentNoaatValidException $e) { catch(\nre\exceptions\AgentNoaatValidException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE); $this->error($e, \nre\core\WebUtils::HTTP_SERVICE_UNAVAILABLE);
} }
catch(\nre\exceptions\AgentNotFoundException $e) { catch(\nre\exceptions\AgentNotFoundException $e) {
$this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND); $this->error($e, \nre\core\WebUtils::HTTP_NOT_FOUND);
} }
catch(\nre\exceptions\ClassNotValidException $e) { catch(\nre\exceptions\ClassNotValidException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\ClassNotFoundException $e) { catch(\nre\exceptions\ClassNotFoundException $e) {
$this->errorService($e); $this->errorService($e);
} }
} }
/** /**
* Render output. * Render output.
*/ */
public function render() public function render()
{ {
// Generate output // Generate output
parent::render(); parent::render();
// Set HTTP-header // Set HTTP-header
$this->response->header(); $this->response->header();
// Show output // Show output
echo $this->response->getOutput(); echo $this->response->getOutput();
} }
/** /**
* Add routes (normal and reverse) defined in the AppConfig. * Add routes (normal and reverse) defined in the AppConfig.
*/ */
private function addRoutes() private function addRoutes()
{ {
// Normal routes // Normal routes
if(property_exists('\nre\configs\AppConfig', 'routes')) { if(property_exists('\nre\configs\AppConfig', 'routes')) {
foreach(\nre\configs\AppConfig::$routes as &$route) { foreach(\nre\configs\AppConfig::$routes as &$route) {
$this->request->addRoute($route[0], $route[1], $route[2]); $this->request->addRoute($route[0], $route[1], $route[2]);
} }
} }
// Reverse routes // Reverse routes
if(property_exists('\nre\configs\AppConfig', 'reverseRoutes')) { if(property_exists('\nre\configs\AppConfig', 'reverseRoutes')) {
foreach(\nre\configs\AppConfig::$reverseRoutes as &$route) { foreach(\nre\configs\AppConfig::$reverseRoutes as &$route) {
$this->request->addReverseRoute($route[0], $route[1], $route[2]); $this->request->addReverseRoute($route[0], $route[1], $route[2]);
} }
} }
// Revalidate request // Revalidate request
$this->request->revalidate(); $this->request->revalidate();
} }
/** /**
* Handle an error that orrcurred during the * Handle an error that orrcurred during the
* loading/constructing/running of the ToplevelAgent. * loading/constructing/running of the ToplevelAgent.
* *
* @param \Exception $exception Occurred exception * @param \Exception $exception Occurred exception
* @param int $httpStatusCode HTTP-statuscode * @param int $httpStatusCode HTTP-statuscode
*/ */
private function error(\nre\core\Exception $exception, $httpStatusCode) private function error(\nre\core\Exception $exception, $httpStatusCode)
{ {
// Log error message // Log error message
$this->log($exception, \nre\core\Logger::LOGMODE_AUTO); $this->log($exception, \nre\core\Logger::LOGMODE_AUTO);
try { try {
// Set agent for handling errors // Set agent for handling errors
$this->response->clearParams(); $this->response->clearParams();
$this->response->addParams( $this->response->addParams(
\nre\configs\AppConfig::$defaults['toplevel-error'], \nre\configs\AppConfig::$defaults['toplevel-error'],
\nre\configs\AppConfig::$defaults['intermediate-error'], \nre\configs\AppConfig::$defaults['intermediate-error'],
\nre\configs\CoreConfig::$defaults['action'], \nre\configs\CoreConfig::$defaults['action'],
$httpStatusCode $httpStatusCode
); );
// Run this agent // Run this agent
parent::run(); parent::run();
} }
catch(\nre\exceptions\ServiceUnavailableException $e) { catch(\nre\exceptions\ServiceUnavailableException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\ActionNotFoundException $e) { catch(\nre\exceptions\ActionNotFoundException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\DatamodelException $e) { catch(\nre\exceptions\DatamodelException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\DriverNotValidException $e) { catch(\nre\exceptions\DriverNotValidException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\DriverNotFoundException $e) { catch(\nre\exceptions\DriverNotFoundException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\ModelNotValidException $e) { catch(\nre\exceptions\ModelNotValidException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\ModelNotFoundException $e) { catch(\nre\exceptions\ModelNotFoundException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\ViewNotFoundException $e) { catch(\nre\exceptions\ViewNotFoundException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\ControllerNotValidException $e) { catch(\nre\exceptions\ControllerNotValidException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\ControllerNotFoundException $e) { catch(\nre\exceptions\ControllerNotFoundException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\AgentNotValidException $e) { catch(\nre\exceptions\AgentNotValidException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(\nre\exceptions\AgentNotFoundException $e) { catch(\nre\exceptions\AgentNotFoundException $e) {
$this->errorService($e); $this->errorService($e);
} }
catch(Exception $e) { catch(Exception $e) {
$this->errorService($e); $this->errorService($e);
} }
} }
/** /**
* Handle a error which cannot be handles by the system (and * Handle a error which cannot be handles by the system (and
* HTTP 503). * HTTP 503).
* *
* @param \Exception $exception Occurred exception * @param \Exception $exception Occurred exception
*/ */
private function errorService($exception) private function errorService($exception)
{ {
// Log error message // Log error message
$this->log($exception, \nre\core\Logger::LOGMODE_AUTO); $this->log($exception, \nre\core\Logger::LOGMODE_AUTO);
// Set HTTP-rtatuscode // Set HTTP-rtatuscode
$this->response->addHeader(\nre\core\WebUtils::getHttpHeader(503)); $this->response->addHeader(\nre\core\WebUtils::getHttpHeader(503));
// Read and print static error file // 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'); $fileName = ROOT.DS.\nre\configs\CoreConfig::getClassDir('views').DS.\nre\configs\CoreConfig::$defaults['errorFile'].\nre\configs\CoreConfig::getFileExt('views');
ob_start(); ob_start();
include($fileName); include($fileName);
$this->response->setOutput(ob_get_clean()); $this->response->setOutput(ob_get_clean());
// Prevent further execution // Prevent further execution
$this->response->setExit(); $this->response->setExit();
} }
} }
?> ?>

View file

@ -1,33 +1,33 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
// Include required classes // Include required classes
require_once(ROOT.DS.'configs'.DS.'CoreConfig.inc'); require_once(ROOT.DS.'configs'.DS.'CoreConfig.inc');
require_once(ROOT.DS.\nre\configs\CoreConfig::getClassDir('core').DS.'Autoloader.inc'); require_once(ROOT.DS.\nre\configs\CoreConfig::getClassDir('core').DS.'Autoloader.inc');
// Set PHP-logging // Set PHP-logging
ini_set('error_log', ROOT.DS.\nre\configs\CoreConfig::getClassDir('logs').DS.'php'.\nre\configs\CoreConfig::getFileExt('logs')); ini_set('error_log', ROOT.DS.\nre\configs\CoreConfig::getClassDir('logs').DS.'php'.\nre\configs\CoreConfig::getFileExt('logs'));
// Register autoloader // Register autoloader
\nre\core\Autoloader::register(); \nre\core\Autoloader::register();
// Initialize WebApi // Initialize WebApi
$webApi = new \nre\apis\WebApi(); $webApi = new \nre\apis\WebApi();
// Run WebApi // Run WebApi
$webApi->run(); $webApi->run();
// Render output // Render output
$webApi->render(); $webApi->render();
?> ?>

View file

@ -1,75 +1,75 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\configs; namespace nre\configs;
/** /**
* Application configuration. * Application configuration.
* *
* This class contains static variables with configuration values for * This class contains static variables with configuration values for
* the specific application. * the specific application.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
final class AppConfig final class AppConfig
{ {
/** /**
* Application values * Application values
* *
* @static * @static
* @var array * @var array
*/ */
public static $app = array( public static $app = array(
//'namespace' => '', //'namespace' => '',
//'timeZone' => '' //'timeZone' => ''
); );
/** /**
* Default values * Default values
* *
* @static * @static
* @var array * @var array
*/ */
public static $defaults = array( public static $defaults = array(
//'toplevel' => '', //'toplevel' => '',
//'toplevel-error' => '', //'toplevel-error' => '',
//'intermediate' => '', //'intermediate' => '',
//'intermediate-error' => '' //'intermediate-error' => ''
); );
/** /**
* Routes * Routes
* *
* @static * @static
* @var array * @var array
*/ */
public static $routes = array( public static $routes = array(
//array('<pattern>', '<replace>', '<is_last>') //array('<pattern>', '<replace>', '<is_last>')
); );
/** /**
* Reverse routes * Reverse routes
* *
* @static * @static
* @var array * @var array
*/ */
public static $reverseRoutes = array( public static $reverseRoutes = array(
//array('<pattern>', '<replace>', '<is_last>') //array('<pattern>', '<replace>', '<is_last>')
); );
} }
?> ?>

View file

@ -1,167 +1,167 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\configs; namespace nre\configs;
/** /**
* Core configuration. * Core configuration.
* *
* This class contains static variables with configuration values. * This class contains static variables with configuration values.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
final class CoreConfig final class CoreConfig
{ {
/** /**
* Core values * Core values
* *
* @static * @static
* @var array * @var array
*/ */
public static $core = array( public static $core = array(
'namespace' => 'nre\\', 'namespace' => 'nre\\',
); );
/** /**
* Directories * Directories
* *
* @static * @static
* @var array * @var array
*/ */
public static $dirs = array( public static $dirs = array(
'core' => 'core', 'core' => 'core',
'publicDir' => 'www' 'publicDir' => 'www'
); );
/** /**
* File extensions * File extensions
* *
* @static * @static
* @var array * @var array
*/ */
public static $fileExts = array( public static $fileExts = array(
'default' => 'inc', 'default' => 'inc',
'views' => 'tpl', 'views' => 'tpl',
'logs' => 'log', 'logs' => 'log',
); );
/** /**
* Default values * Default values
* *
* @static * @static
* @var array * @var array
*/ */
public static $defaults = array( public static $defaults = array(
'action' => 'index', 'action' => 'index',
'errorFile' => 'error', 'errorFile' => 'error',
'inlineErrorFile' => 'inlineerror' 'inlineErrorFile' => 'inlineerror'
); );
/** /**
* Miscellaneous settings * Miscellaneous settings
* *
* @static * @static
* @var array * @var array
*/ */
public static $misc = array( public static $misc = array(
'fileExtDot' => '.' 'fileExtDot' => '.'
); );
/** /**
* Logging settings * Logging settings
* *
* @static * @static
* @var array * @var array
*/ */
public static $log = array( public static $log = array(
'filename' => 'errors', 'filename' => 'errors',
'format' => 'Fehler %d: %s in %s, Zeile %d' 'format' => 'Fehler %d: %s in %s, Zeile %d'
); );
/** /**
* Class-specific settings * Class-specific settings
* *
* @static * @static
* @var array * @var array
*/ */
public static $classes = array( public static $classes = array(
'linker' => array( 'linker' => array(
'url' => array( 'url' => array(
'length' => 128, 'length' => 128,
'delimiter' => '-' 'delimiter' => '-'
) )
) )
); );
/** /**
* Determine the directory for a specific classtype. * Determine the directory for a specific classtype.
* *
* @param string $classType Classtype to get directory of * @param string $classType Classtype to get directory of
* @return string Directory of given classtype * @return string Directory of given classtype
*/ */
public static function getClassDir($classType) public static function getClassDir($classType)
{ {
// Default directory (for core classes) // Default directory (for core classes)
$classDir = self::$dirs['core']; $classDir = self::$dirs['core'];
// Configurable directory // Configurable directory
if(array_key_exists($classType, self::$dirs)) { if(array_key_exists($classType, self::$dirs)) {
$classDir = self::$dirs[$classType]; $classDir = self::$dirs[$classType];
} }
else else
{ {
// Default directory for classtype // Default directory for classtype
if(is_dir(ROOT.DS.$classType)) { if(is_dir(ROOT.DS.$classType)) {
$classDir = $classType; $classDir = $classType;
} }
} }
// Return directory // Return directory
return $classDir; return $classDir;
} }
/** /**
* Determine the file extension for a specific filetype. * Determine the file extension for a specific filetype.
* *
* @param string $fileType Filetype to get file extension of * @param string $fileType Filetype to get file extension of
* @return string File extension of given filetype * @return string File extension of given filetype
*/ */
public static function getFileExt($fileType) public static function getFileExt($fileType)
{ {
// Default file extension // Default file extension
$fileExt = self::$fileExts['default']; $fileExt = self::$fileExts['default'];
// Configurable file extension // Configurable file extension
if(array_key_exists($fileType, self::$fileExts)) { if(array_key_exists($fileType, self::$fileExts)) {
$fileExt = self::$fileExts[$fileType]; $fileExt = self::$fileExts[$fileType];
} }
// Return file extension // Return file extension
return self::$misc['fileExtDot'].$fileExt; return self::$misc['fileExtDot'].$fileExt;
} }
} }
?> ?>

File diff suppressed because it is too large Load diff

View file

@ -1,163 +1,163 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Abstract class to implement an API. * Abstract class to implement an API.
* *
* The API is the center of each application and specifies how and what * The API is the center of each application and specifies how and what
* to run and render. * to run and render.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
abstract class Api abstract class Api
{ {
/** /**
* Die aktuelle Anfrage * Die aktuelle Anfrage
* *
* @var Request * @var Request
*/ */
protected $request; protected $request;
/** /**
* Der Toplevelagent * Der Toplevelagent
* *
* @var \nre\agents\ToplevelAgent * @var \nre\agents\ToplevelAgent
*/ */
private $toplevelAgent = null; private $toplevelAgent = null;
/** /**
* Die aktuelle Antwort * Die aktuelle Antwort
* *
* @var Response * @var Response
*/ */
protected $response; protected $response;
/** /**
* Log-System * Log-System
* *
* @var Logger * @var Logger
*/ */
protected $log; protected $log;
/** /**
* Construct a new API. * Construct a new API.
* *
* @param Request $request Current request * @param Request $request Current request
* @param Response $response Current response * @param Response $response Current response
*/ */
public function __construct(Request $request, Response $response) public function __construct(Request $request, Response $response)
{ {
// Store request // Store request
$this->request = $request; $this->request = $request;
// Store response // Store response
$this->response = $response; $this->response = $response;
// Init logging // Init logging
$this->log = new \nre\core\Logger(); $this->log = new \nre\core\Logger();
} }
/** /**
* Run the application. * Run the application.
* *
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @throws \nre\exceptions\DriverNotValidException * @throws \nre\exceptions\DriverNotValidException
* @throws \nre\exceptions\DriverNotFoundException * @throws \nre\exceptions\DriverNotFoundException
* @throws \nre\exceptions\ViewNotFoundException * @throws \nre\exceptions\ViewNotFoundException
* @throws \nre\exceptions\ModelNotValidException * @throws \nre\exceptions\ModelNotValidException
* @throws \nre\exceptions\ModelNotFoundException * @throws \nre\exceptions\ModelNotFoundException
* @throws \nre\exceptions\ControllerNotValidException * @throws \nre\exceptions\ControllerNotValidException
* @throws \nre\exceptions\ControllerNotFoundException * @throws \nre\exceptions\ControllerNotFoundException
* @throws \nre\exceptions\AgentNotValidException * @throws \nre\exceptions\AgentNotValidException
* @throws \nre\exceptions\AgentNotFoundException * @throws \nre\exceptions\AgentNotFoundException
* @return \Exception Last occurred exception of an subagent * @return \Exception Last occurred exception of an subagent
*/ */
public function run() public function run()
{ {
// Load ToplevelAgent // Load ToplevelAgent
$this->loadToplevelAgent(); $this->loadToplevelAgent();
// Run ToplevelAgent // Run ToplevelAgent
return $this->toplevelAgent->run($this->request, $this->response); return $this->toplevelAgent->run($this->request, $this->response);
} }
/** /**
* Render the output. * Render the output.
*/ */
public function render() public function render()
{ {
// Check exit-status // Check exit-status
if($this->response->getExit()) { if($this->response->getExit()) {
return; return;
} }
// Render ToplevelAgent // Render ToplevelAgent
$this->response->setOutput($this->toplevelAgent->render()); $this->response->setOutput($this->toplevelAgent->render());
} }
/** /**
* Log an exception * Log an exception
* *
* @param \Exception $exception Occurred exception * @param \Exception $exception Occurred exception
* @param int $logMode Log-mode * @param int $logMode Log-mode
*/ */
protected function log($exception, $logMode) protected function log($exception, $logMode)
{ {
$this->log->log( $this->log->log(
$exception->getMessage(), $exception->getMessage(),
$logMode $logMode
); );
} }
/** /**
* Load the ToplevelAgent specified by the request. * Load the ToplevelAgent specified by the request.
* *
* @throws \nre\exceptions\ServiceUnavailableException * @throws \nre\exceptions\ServiceUnavailableException
* @throws \nre\exceptions\AgentNotValidException * @throws \nre\exceptions\AgentNotValidException
* @throws \nre\exceptions\AgentNotFoundException * @throws \nre\exceptions\AgentNotFoundException
*/ */
private function loadToplevelAgent() private function loadToplevelAgent()
{ {
// Determine agent // Determine agent
$agentName = $this->response->getParam(0); $agentName = $this->response->getParam(0);
if(is_null($agentName)) { if(is_null($agentName)) {
$agentName = $this->request->getParam(0, 'toplevel'); $agentName = $this->request->getParam(0, 'toplevel');
$this->response->addParam($agentName); $this->response->addParam($agentName);
} }
// Load agent // Load agent
\nre\agents\ToplevelAgent::load($agentName); \nre\agents\ToplevelAgent::load($agentName);
// Construct agent // Construct agent
$this->toplevelAgent = \nre\agents\ToplevelAgent::factory( $this->toplevelAgent = \nre\agents\ToplevelAgent::factory(
$agentName, $agentName,
$this->request, $this->request,
$this->response, $this->response,
$this->log $this->log
); );
} }
} }
?> ?>

View file

@ -1,98 +1,98 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Autoloader. * Autoloader.
* *
* This class tries to load not yet used classes. * This class tries to load not yet used classes.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class Autoloader class Autoloader
{ {
/** /**
* Private construct(). * Private construct().
*/ */
private function __construct() {} private function __construct() {}
/** /**
* Private clone(). * Private clone().
*/ */
private function __clone() {} private function __clone() {}
/** /**
* Register load-method. * Register load-method.
*/ */
public static function register() public static function register()
{ {
spl_autoload_register( spl_autoload_register(
array( array(
get_class(), get_class(),
'load' 'load'
) )
); );
} }
/** /**
* Look for the given class and try to load it. * Look for the given class and try to load it.
* *
* @param string $fullClassName Die zu ladende Klasse * @param string $fullClassName Name of class to load
*/ */
public static function load($fullClassName) public static function load($fullClassName)
{ {
$fullClassNameA = explode('\\', $fullClassName); $fullClassNameA = explode('\\', $fullClassName);
if(strpos($fullClassName, \nre\configs\CoreConfig::$core['namespace']) !== 0) if(strpos($fullClassName, \nre\configs\CoreConfig::$core['namespace']) !== 0)
{ {
// App // App
$className = array_slice($fullClassNameA, substr_count(\nre\configs\AppConfig::$app['namespace'], '\\')); $className = array_slice($fullClassNameA, substr_count(\nre\configs\AppConfig::$app['namespace'], '\\'));
array_unshift($className, \nre\configs\CoreConfig::getClassDir('app')); array_unshift($className, \nre\configs\CoreConfig::getClassDir('app'));
$filename = ROOT.DS.implode(DS, $className).\nre\configs\CoreConfig::getFileExt('includes'); $filename = ROOT.DS.implode(DS, $className).\nre\configs\CoreConfig::getFileExt('includes');
if(file_exists($filename)) { if(file_exists($filename)) {
require_once($filename); require_once($filename);
} }
} }
else else
{ {
// Core // Core
$className = array_slice($fullClassNameA, substr_count(\nre\configs\CoreConfig::$core['namespace'], '\\')); $className = array_slice($fullClassNameA, substr_count(\nre\configs\CoreConfig::$core['namespace'], '\\'));
$filename = ROOT.DS.implode(DS, $className).\nre\configs\CoreConfig::getFileExt('includes'); $filename = ROOT.DS.implode(DS, $className).\nre\configs\CoreConfig::getFileExt('includes');
if(file_exists($filename)) { if(file_exists($filename)) {
require_once($filename); require_once($filename);
} }
} }
} }
/** /**
* Determine classtype of a class. * Determine classtype of a class.
* *
* @param string $className Name of the class to determine the classtype of * @param string $className Name of the class to determine the classtype of
* @return string Classtype of the given class * @return string Classtype of the given class
*/ */
public static function getClassType($className) public static function getClassType($className)
{ {
// CamelCase // CamelCase
return strtolower(preg_replace('/^.*([A-Z][^A-Z]+)$/', '$1', $className)); return strtolower(preg_replace('/^.*([A-Z][^A-Z]+)$/', '$1', $className));
} }
} }
?> ?>

View file

@ -1,129 +1,129 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Class for safely loading classes. * Class for safely loading classes.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ClassLoader class ClassLoader
{ {
/** /**
* Load a class. * Load a class.
* *
* @throws \nre\exceptions\ClassNotFoundException * @throws \nre\exceptions\ClassNotFoundException
* @param string $className Name of the class to load * @param string $className Name of the class to load
*/ */
public static function load($fullClassName) public static function load($fullClassName)
{ {
// Determine folder to look in // Determine folder to look in
$className = explode('\\', $fullClassName); $className = explode('\\', $fullClassName);
$className = array_slice($className, substr_count(\nre\configs\AppConfig::$app['namespace'], '\\')); $className = array_slice($className, substr_count(\nre\configs\AppConfig::$app['namespace'], '\\'));
// Determine filename // Determine filename
$fileName = ROOT.DS.implode(DS, $className). \nre\configs\CoreConfig::getFileExt('includes'); $fileName = ROOT.DS.implode(DS, $className). \nre\configs\CoreConfig::getFileExt('includes');
// Check file // Check file
if(!file_exists($fileName)) if(!file_exists($fileName))
{ {
throw new \nre\exceptions\ClassNotFoundException( throw new \nre\exceptions\ClassNotFoundException(
$fullClassName $fullClassName
); );
} }
// Include file // Include file
include_once($fileName); include_once($fileName);
} }
/** /**
* Check inheritance of a class. * Check inheritance of a class.
* *
* @throws \nre\exceptions\ClassNotValidException * @throws \nre\exceptions\ClassNotValidException
* @param string $className Name of the class to check * @param string $className Name of the class to check
* @param string $parentClassName Name of the parent class * @param string $parentClassName Name of the parent class
*/ */
public static function check($className, $parentClassName) public static function check($className, $parentClassName)
{ {
// Check if class is subclass of parent class // Check if class is subclass of parent class
if(!is_subclass_of($className, $parentClassName)) { if(!is_subclass_of($className, $parentClassName)) {
throw new \nre\exceptions\ClassNotValidException( throw new \nre\exceptions\ClassNotValidException(
$className $className
); );
} }
} }
/** /**
* Strip the namespace from a class name. * Strip the namespace from a class name.
* *
* @param string $class Name of a class including its namespace * @param string $class Name of a class including its namespace
* @return Name of the given class without its namespace * @return string Name of the given class without its namespace
*/ */
public static function stripNamespace($class) public static function stripNamespace($class)
{ {
return array_slice(explode('\\', $class), -1)[0]; return array_slice(explode('\\', $class), -1)[0];
} }
/** /**
* Strip the class type from a class name. * Strip the class type from a class name.
* *
* @param string $className Name of a class * @param string $className Name of a class
* @return Name of the given class without its class type * @return string Name of the given class without its class type
*/ */
public static function stripClassType($className) public static function stripClassType($className)
{ {
return preg_replace('/^(.*)[A-Z][^A-Z]+$/', '$1', $className); return preg_replace('/^(.*)[A-Z][^A-Z]+$/', '$1', $className);
} }
/** /**
* Strip the namespace and the class type of a full class name * Strip the namespace and the class type of a full class name
* to get only its name. * to get only its name.
* *
* @param string $class Full name of a class * @param string $class Full name of a class
* @return Only the name of the given class * @return string Only the name of the given class
*/ */
public static function getClassName($class) public static function getClassName($class)
{ {
return self::stripClassType(self::stripNamespace($class)); return self::stripClassType(self::stripNamespace($class));
} }
/** /**
* Concatenate strings to a class name following the CamelCase * Concatenate strings to a class name following the CamelCase
* pattern. * pattern.
* *
* @param string $className1 Arbitrary number of strings to concat * @param string $className1 Arbitrary number of strings to concat
* @return string Class name as CamelCase * @return string Class name as CamelCase
*/ */
public static function concatClassNames($className1) public static function concatClassNames($className1)
{ {
return implode('', array_map( return implode('', array_map(
function($arg) { function($arg) {
return ucfirst(strtolower($arg)); return ucfirst(strtolower($arg));
}, },
func_get_args() func_get_args()
)); ));
} }
} }
?> ?>

View file

@ -1,85 +1,85 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Abstract class to implement a (Controller) Component. * Abstract class to implement a (Controller) Component.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
abstract class Component abstract class Component
{ {
/** /**
* Load the class of a Component. * Load the class of a Component.
* *
* @throws \nre\exceptions\ComponentNotFoundException * @throws \nre\exceptions\ComponentNotFoundException
* @throws \nre\exceptions\ComponentNotValidException * @throws \nre\exceptions\ComponentNotValidException
* @param string $componentName Name of the Component to load * @param string $componentName Name of the Component to load
*/ */
public static function load($componentName) public static function load($componentName)
{ {
// Determine full classname // Determine full classname
$className = self::getClassName($componentName); $className = self::getClassName($componentName);
try { try {
// Load class // Load class
ClassLoader::load($className); ClassLoader::load($className);
// Validate class // Validate class
ClassLoader::check($className, get_class()); ClassLoader::check($className, get_class());
} }
catch(\nre\exceptions\ClassNotValidException $e) { catch(\nre\exceptions\ClassNotValidException $e) {
throw new \nre\exceptions\ComponentNotValidException($e->getClassName()); throw new \nre\exceptions\ComponentNotValidException($e->getClassName());
} }
catch(\nre\exceptions\ClassNotFoundException $e) { catch(\nre\exceptions\ClassNotFoundException $e) {
throw new \nre\exceptions\ComponentNotFoundException($e->getClassName()); throw new \nre\exceptions\ComponentNotFoundException($e->getClassName());
} }
} }
/** /**
* Instantiate a Component (Factory Pattern). * Instantiate a Component (Factory Pattern).
* *
* @param string $componentName Name of the Component to instantiate * @param string $componentName Name of the Component to instantiate
*/ */
public static function factory($componentName) public static function factory($componentName)
{ {
// Determine full classname // Determine full classname
$className = self::getClassName($componentName); $className = self::getClassName($componentName);
// Construct and return Controller // Construct and return Controller
return new $className(); return new $className();
} }
/** /**
* Determine the classname for the given Component name. * Determine the classname for the given Component name.
* *
* @param string $componentName Component name to get classname of * @param string $componentName Component name to get classname of
* @return string Classname for the Component name * @return string Classname for the Component name
*/ */
private static function getClassName($componentName) private static function getClassName($componentName)
{ {
$className = \nre\core\ClassLoader::concatClassNames($componentName, \nre\core\ClassLoader::stripNamespace(get_class())); $className = \nre\core\ClassLoader::concatClassNames($componentName, \nre\core\ClassLoader::stripNamespace(get_class()));
return \nre\configs\AppConfig::$app['namespace']."controllers\\components\\$className"; return \nre\configs\AppConfig::$app['namespace']."controllers\\components\\$className";
} }
} }
?> ?>

View file

@ -1,49 +1,49 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Configuration. * Configuration.
* *
* This class does not hold any configuration value but helps to * This class does not hold any configuration value but helps to
* determine values that can be hold by AppConfig or CoreConfig. * determine values that can be hold by AppConfig or CoreConfig.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
final class Config final class Config
{ {
/** /**
* Get a default value. * Get a default value.
* *
* @param string $index Index of value to get * @param string $index Index of value to get
*/ */
public static function getDefault($index) public static function getDefault($index)
{ {
if(array_key_exists($index, \nre\configs\AppConfig::$defaults)) { if(array_key_exists($index, \nre\configs\AppConfig::$defaults)) {
return \nre\configs\AppConfig::$defaults[$index]; return \nre\configs\AppConfig::$defaults[$index];
} }
if(array_key_exists($index, \nre\configs\CoreConfig::$defaults)) { if(array_key_exists($index, \nre\configs\CoreConfig::$defaults)) {
return \nre\configs\CoreConfig::$defaults[$index]; return \nre\configs\CoreConfig::$defaults[$index];
} }
return null; return null;
} }
} }
?> ?>

View file

@ -1,431 +1,431 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Abstract class for implementing a Controller. * Abstract class for implementing a Controller.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
abstract class Controller abstract class Controller
{ {
/** /**
* Corresponding Agent * Corresponding Agent
* *
* @var Agent * @var Agent
*/ */
protected $agent; protected $agent;
/** /**
* View of the Controller * View of the Controller
* *
* @var View * @var View
*/ */
protected $view = null; protected $view = null;
/** /**
* Data to pass to the View * Data to pass to the View
* *
* @var array * @var array
*/ */
protected $viewData = array(); protected $viewData = array();
/** /**
* Current request * Current request
* *
* @var Request * @var Request
*/ */
protected $request = null; protected $request = null;
/** /**
* Current response * Current response
* *
* @var Response * @var Response
*/ */
protected $response = null; protected $response = null;
/** /**
* Load the class of a Controller. * Load the class of a Controller.
* *
* @throws \nre\exceptions\ControllerNotFoundException * @throws \nre\exceptions\ControllerNotFoundException
* @throws \nre\exceptions\ControllerNotValidException * @throws \nre\exceptions\ControllerNotValidException
* @param string $controllerName Name of the Controller to load * @param string $controllerName Name of the Controller to load
*/ */
public static function load($controllerName) public static function load($controllerName)
{ {
// Determine full classname // Determine full classname
$className = self::getClassName($controllerName); $className = self::getClassName($controllerName);
try { try {
// Load class // Load class
ClassLoader::load($className); ClassLoader::load($className);
// Validate class // Validate class
ClassLoader::check($className, get_class()); ClassLoader::check($className, get_class());
} }
catch(\nre\exceptions\ClassNotValidException $e) { catch(\nre\exceptions\ClassNotValidException $e) {
throw new \nre\exceptions\ControllerNotValidException($e->getClassName()); throw new \nre\exceptions\ControllerNotValidException($e->getClassName());
} }
catch(\nre\exceptions\ClassNotFoundException $e) { catch(\nre\exceptions\ClassNotFoundException $e) {
throw new \nre\exceptions\ControllerNotFoundException($e->getClassName()); throw new \nre\exceptions\ControllerNotFoundException($e->getClassName());
} }
} }
/** /**
* Instantiate a Controller (Factory Pattern). * Instantiate a Controller (Factory Pattern).
* *
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @throws \nre\exceptions\DriverNotFoundException * @throws \nre\exceptions\DriverNotFoundException
* @throws \nre\exceptions\DriverNotValidException * @throws \nre\exceptions\DriverNotValidException
* @throws \nre\exceptions\ModelNotValidException * @throws \nre\exceptions\ModelNotValidException
* @throws \nre\exceptions\ModelNotFoundException * @throws \nre\exceptions\ModelNotFoundException
* @throws \nre\exceptions\ViewNotFoundException * @throws \nre\exceptions\ViewNotFoundException
* @param string $controllerName Name of the Controller to instantiate * @param string $controllerName Name of the Controller to instantiate
* @param string $layoutName Name of the current Layout * @param string $layoutName Name of the current Layout
* @param string $action Current Action * @param string $action Current Action
* @param string $agent Corresponding Agent * @param string $agent Corresponding Agent
*/ */
public static function factory($controllerName, $layoutName, $action, $agent) public static function factory($controllerName, $layoutName, $action, $agent)
{ {
// Determine full classname // Determine full classname
$className = self::getClassName($controllerName); $className = self::getClassName($controllerName);
// Construct and return Controller // Construct and return Controller
return new $className($layoutName, $action, $agent); return new $className($layoutName, $action, $agent);
} }
/** /**
* Determine the classname for the given Controller name. * Determine the classname for the given Controller name.
* *
* @param string $controllerName Controller name to get classname of * @param string $controllerName Controller name to get classname of
* @return string Classname for the Controller name * @return string Classname for the Controller name
*/ */
private static function getClassName($controllerName) private static function getClassName($controllerName)
{ {
$className = \nre\core\ClassLoader::concatClassNames($controllerName, \nre\core\ClassLoader::stripNamespace(get_class())); $className = \nre\core\ClassLoader::concatClassNames($controllerName, \nre\core\ClassLoader::stripNamespace(get_class()));
return \nre\configs\AppConfig::$app['namespace']."controllers\\$className"; return \nre\configs\AppConfig::$app['namespace']."controllers\\$className";
} }
/** /**
* Construct a new Controller. * Construct a new Controller.
* *
* @throws \nre\exceptions\DriverNotFoundException * @throws \nre\exceptions\DriverNotFoundException
* @throws \nre\exceptions\DriverNotValidException * @throws \nre\exceptions\DriverNotValidException
* @throws \nre\exceptions\ModelNotValidException * @throws \nre\exceptions\ModelNotValidException
* @throws \nre\exceptions\ModelNotFoundException * @throws \nre\exceptions\ModelNotFoundException
* @throws \nre\exceptions\ViewNotFoundException * @throws \nre\exceptions\ViewNotFoundException
* @param string $layoutName Name of the current Layout * @param string $layoutName Name of the current Layout
* @param string $action Current Action * @param string $action Current Action
* @param Agent $agent Corresponding Agent * @param Agent $agent Corresponding Agent
*/ */
protected function __construct($layoutName, $action, $agent) protected function __construct($layoutName, $action, $agent)
{ {
// Store values // Store values
$this->agent = $agent; $this->agent = $agent;
// Load Components // Load Components
$this->loadComponents(); $this->loadComponents();
// Load Models // Load Models
$this->loadModels(); $this->loadModels();
// Load View // Load View
$this->loadView($layoutName, $action); $this->loadView($layoutName, $action);
} }
/** /**
* Prefilter that is executed before running the Controller. * Prefilter that is executed before running the Controller.
* *
* @param Request $request Current request * @param Request $request Current request
* @param Response $response Current response * @param Response $response Current response
*/ */
public function preFilter(Request $request, Response $response) public function preFilter(Request $request, Response $response)
{ {
// Request speichern // Request speichern
$this->request = $request; $this->request = $request;
// Response speichern // Response speichern
$this->response = $response; $this->response = $response;
} }
/** /**
* Prefilter that is executed after running the Controller. * Prefilter that is executed after running the Controller.
* *
* @param Request $request Current request * @param Request $request Current request
* @param Response $response Current response * @param Response $response Current response
*/ */
public function postFilter(Request $request, Response $response) public function postFilter(Request $request, Response $response)
{ {
} }
/** /**
* Run the Controller. * Run the Controller.
* *
* This method executes the Action of the Controller defined by * This method executes the Action of the Controller defined by
* the current Request. * the current Request.
* *
* @throws \nre\exceptions\ParamsNotValidException * @throws \nre\exceptions\ParamsNotValidException
* @throws \nre\exceptions\IdNotFoundException * @throws \nre\exceptions\IdNotFoundException
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @throws \nre\exceptions\ActionNotFoundException * @throws \nre\exceptions\ActionNotFoundException
* @param Request $request Current request * @param Request $request Current request
* @param Response $response Current response * @param Response $response Current response
*/ */
public function run(Request $request, Response $response) public function run(Request $request, Response $response)
{ {
// Determine Action // Determine Action
$action = $response->getParam(2, 'action'); $action = $response->getParam(2, 'action');
if(!method_exists($this, $action)) { if(!method_exists($this, $action)) {
throw new \nre\exceptions\ActionNotFoundException($action); throw new \nre\exceptions\ActionNotFoundException($action);
} }
// Determine parameters // Determine parameters
$params = $response->getParams(3); $params = $response->getParams(3);
if(empty($params)) { if(empty($params)) {
$params = $request->getParams(3); $params = $request->getParams(3);
} }
// Fill missing parameters // Fill missing parameters
$rc = new \ReflectionClass($this); $rc = new \ReflectionClass($this);
$nullParamsCount = $rc->getMethod($action)->getNumberOfParameters() - count($params); $nullParamsCount = $rc->getMethod($action)->getNumberOfParameters() - count($params);
$nullParams = ($nullParamsCount > 0 ? array_fill(0, $nullParamsCount, NULL) : array()); $nullParams = ($nullParamsCount > 0 ? array_fill(0, $nullParamsCount, NULL) : array());
// Call Action // Call Action
call_user_func_array( call_user_func_array(
array( array(
$this, $this,
$action $action
), ),
array_merge( array_merge(
$params, $params,
$nullParams $nullParams
) )
); );
} }
/** /**
* Generate the output. * Generate the output.
* *
* @param array $viewData Data to pass to the View * @param array $viewData Data to pass to the View
* @return string Generated output * @return string Generated output
*/ */
public function render($viewData=null) public function render($viewData=null)
{ {
// Combine given data and data of this Controller // Combine given data and data of this Controller
$data = $this->viewData; $data = $this->viewData;
if(!is_null($viewData)) { if(!is_null($viewData)) {
$data = array_merge($viewData, $data); $data = array_merge($viewData, $data);
} }
// Rendern and return output // Rendern and return output
return $this->view->render($data); return $this->view->render($data);
} }
/** /**
* Set data for the View. * Set data for the View.
* *
* @param string $name Key * @param string $name Key
* @param mixed $data Value * @param mixed $data Value
*/ */
protected function set($name, $data) protected function set($name, $data)
{ {
$this->viewData[$name] = $data; $this->viewData[$name] = $data;
} }
/** /**
* Redirect to the given URL. * Redirect to the given URL.
* *
* @param string $url Relative URL * @param string $url Relative URL
*/ */
protected function redirect($url) protected function redirect($url)
{ {
$url = 'http://'.$_SERVER['HTTP_HOST'].$url; $url = 'http://'.$_SERVER['HTTP_HOST'].$url;
header('Location: '.$url); header('Location: '.$url);
exit; exit;
} }
/** /**
* Check if Models of this Controller are loaded and available. * Check if Models of this Controller are loaded and available.
* *
* @param string $modelName Arbitrary number of Models to check * @param string $modelName Arbitrary number of Models to check
* @return bool All given Models are loaded and available * @return bool All given Models are loaded and available
*/ */
protected function checkModels($modelName) protected function checkModels($modelName)
{ {
foreach(func_get_args() as $modelName) foreach(func_get_args() as $modelName)
{ {
if(!isset($this->$modelName) || !is_subclass_of($this->$modelName, 'Model')) { if(!isset($this->$modelName) || !is_subclass_of($this->$modelName, 'Model')) {
return false; return false;
} }
} }
return true; return true;
} }
/** /**
* Get the View of the Controller * Get the View of the Controller
* *
* @return View View of the Controller * @return View View of the Controller
*/ */
protected function getView() protected function getView()
{ {
return $this->view; return $this->view;
} }
/** /**
* Load the Components of this Controller. * Load the Components of this Controller.
* *
* @throws \nre\exceptions\ComponentNotValidException * @throws \nre\exceptions\ComponentNotValidException
* @throws \nre\exceptions\ComponentNotFoundException * @throws \nre\exceptions\ComponentNotFoundException
*/ */
private function loadComponents() private function loadComponents()
{ {
// Determine components // Determine components
$components = array(); $components = array();
if(property_exists($this, 'components')) { if(property_exists($this, 'components')) {
$components = $this->components; $components = $this->components;
} }
if(!is_array($components)) { if(!is_array($components)) {
$components = array($components); $components = array($components);
} }
// Components of parent classes // Components of parent classes
$parent = $this; $parent = $this;
while($parent = get_parent_class($parent)) while($parent = get_parent_class($parent))
{ {
$properties = get_class_vars($parent); $properties = get_class_vars($parent);
if(array_key_exists('components', $properties)) { if(array_key_exists('components', $properties)) {
$components = array_merge($components, $properties['components']); $components = array_merge($components, $properties['components']);
} }
} }
// Load components // Load components
foreach($components as &$component) foreach($components as &$component)
{ {
// Load class // Load class
Component::load($component); Component::load($component);
// Construct component // Construct component
$componentName = ucfirst(strtolower($component)); $componentName = ucfirst(strtolower($component));
$this->$componentName = Component::factory($component); $this->$componentName = Component::factory($component);
} }
} }
/** /**
* Load the Models of this Controller. * Load the Models of this Controller.
* *
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @throws \nre\exceptions\DriverNotFoundException * @throws \nre\exceptions\DriverNotFoundException
* @throws \nre\exceptions\DriverNotValidException * @throws \nre\exceptions\DriverNotValidException
* @throws \nre\exceptions\ModelNotValidException * @throws \nre\exceptions\ModelNotValidException
* @throws \nre\exceptions\ModelNotFoundException * @throws \nre\exceptions\ModelNotFoundException
*/ */
protected function loadModels() protected function loadModels()
{ {
// Determine Models // Determine Models
$explicit = false; $explicit = false;
$models = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class($this))); $models = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class($this)));
if(property_exists($this, 'models')) if(property_exists($this, 'models'))
{ {
$models = $this->models; $models = $this->models;
$explicit = true; $explicit = true;
} }
if(!is_array($models)) { if(!is_array($models)) {
$models = array($models); $models = array($models);
} }
// Models of parent classes // Models of parent classes
$parent = $this; $parent = $this;
while($parent = get_parent_class($parent)) while($parent = get_parent_class($parent))
{ {
$properties = get_class_vars($parent); $properties = get_class_vars($parent);
if(array_key_exists('models', $properties)) { if(array_key_exists('models', $properties)) {
$models = array_merge($models, $properties['models']); $models = array_merge($models, $properties['models']);
} }
} }
$models = array_unique($models); $models = array_unique($models);
// Load Models // Load Models
foreach($models as &$model) foreach($models as &$model)
{ {
try { try {
// Load class // Load class
Model::load($model); Model::load($model);
// Construct Model // Construct Model
$modelName = ucfirst(strtolower($model)); $modelName = ucfirst(strtolower($model));
$this->$modelName = Model::factory($model); $this->$modelName = Model::factory($model);
} }
catch(\nre\exceptions\ModelNotValidException $e) { catch(\nre\exceptions\ModelNotValidException $e) {
if($explicit) { if($explicit) {
throw $e; throw $e;
} }
} }
catch(\nre\exceptions\ModelNotFoundException $e) { catch(\nre\exceptions\ModelNotFoundException $e) {
if($explicit) { if($explicit) {
throw $e; throw $e;
} }
} }
} }
} }
/** /**
* Load the View of this Controller. * Load the View of this Controller.
* *
* @throws \nre\exceptions\ViewNotFoundException * @throws \nre\exceptions\ViewNotFoundException
* @param string $layoutName Name of the current Layout * @param string $layoutName Name of the current Layout
* @param string $action Current Action * @param string $action Current Action
*/ */
protected function loadView($layoutName, $action) protected function loadView($layoutName, $action)
{ {
// Check Layout name // Check Layout name
if(is_null($layoutName)) { if(is_null($layoutName)) {
return; return;
} }
// Determine controller name // Determine controller name
$controllerName = \nre\core\ClassLoader::getClassName(get_class($this)); $controllerName = \nre\core\ClassLoader::getClassName(get_class($this));
// Load view // Load view
$isToplevel = is_subclass_of($this->agent, '\nre\agents\ToplevelAgent'); $isToplevel = is_subclass_of($this->agent, '\nre\agents\ToplevelAgent');
$this->view = View::loadAndFactory($layoutName, $controllerName, $action, $isToplevel); $this->view = View::loadAndFactory($layoutName, $controllerName, $action, $isToplevel);
} }
} }
?> ?>

View file

@ -1,97 +1,97 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Abstract class for implementing a Driver. * Abstract class for implementing a Driver.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
abstract class Driver abstract class Driver
{ {
/** /**
* Load the class of a Driver. * Load the class of a Driver.
* *
* @throws \nre\exceptions\DriverNotFoundException * @throws \nre\exceptions\DriverNotFoundException
* @throws \nre\exceptions\DriverNotValidException * @throws \nre\exceptions\DriverNotValidException
* @param string $driverName Name of the Driver to load * @param string $driverName Name of the Driver to load
*/ */
public static function load($driverName) public static function load($driverName)
{ {
// Determine full classname // Determine full classname
$className = self::getClassName($driverName); $className = self::getClassName($driverName);
try { try {
// Load class // Load class
ClassLoader::load($className); ClassLoader::load($className);
// Validate class // Validate class
ClassLoader::check($className, get_class()); ClassLoader::check($className, get_class());
} }
catch(\nre\exceptions\ClassNotValidException $e) { catch(\nre\exceptions\ClassNotValidException $e) {
throw new \nre\exceptions\DriverNotValidException($e->getClassName()); throw new \nre\exceptions\DriverNotValidException($e->getClassName());
} }
catch(\nre\exceptions\ClassNotFoundException $e) { catch(\nre\exceptions\ClassNotFoundException $e) {
throw new \nre\exceptions\DriverNotFoundException($e->getClassName()); throw new \nre\exceptions\DriverNotFoundException($e->getClassName());
} }
} }
/** /**
* Instantiate a Driver (Factory Pattern). * Instantiate a Driver (Factory Pattern).
* *
* @param string $driverName Name of the Driver to instantiate * @param string $driverName Name of the Driver to instantiate
* @param array $config Configuration settings * @param array $config Configuration settings
*/ */
public static function factory($driverName, $config) public static function factory($driverName, $config)
{ {
// Determine full classname // Determine full classname
$className = self::getClassName($driverName); $className = self::getClassName($driverName);
// Construct and return Driver // Construct and return Driver
return $className::singleton($config); return $className::singleton($config);
} }
/** /**
* Determine the classname for the given Driver name. * Determine the classname for the given Driver name.
* *
* @param string $driverName Driver name to get classname of * @param string $driverName Driver name to get classname of
* @return string Classname fore the Driver name * @return string Classname fore the Driver name
*/ */
private static function getClassName($driverName) private static function getClassName($driverName)
{ {
$className = ClassLoader::concatClassNames($driverName, ClassLoader::stripNamespace(get_class())); $className = ClassLoader::concatClassNames($driverName, ClassLoader::stripNamespace(get_class()));
return "\\nre\\drivers\\$className"; return "\\nre\\drivers\\$className";
} }
/** /**
* Construct a new Driver. * Construct a new Driver.
*/ */
protected function __construct() protected function __construct()
{ {
} }
} }
?> ?>

View file

@ -1,65 +1,65 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Exception class. * Exception class.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class Exception extends \Exception class Exception extends \Exception
{ {
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $message Error message * @param string $message Error message
* @param int $code Error code * @param int $code Error code
* @param string $name Name to insert * @param string $name Name to insert
*/ */
function __construct($message, $code, $name=null) function __construct($message, $code, $name=null)
{ {
parent::__construct( parent::__construct(
$this->concat( $this->concat(
$message, $message,
$name $name
), ),
$code $code
); );
} }
/** /**
* Insert the name in a message * Insert the name in a message
* *
* @param string $message Error message * @param string $message Error message
* @param string $name Name to insert * @param string $name Name to insert
*/ */
private function concat($message, $name) private function concat($message, $name)
{ {
if(is_null($name)) { if(is_null($name)) {
return $message; return $message;
} }
return "$message: $name"; return "$message: $name";
} }
} }
?> ?>

View file

@ -1,313 +1,313 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Class to create web links based on the current request. * Class to create web links based on the current request.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class Linker class Linker
{ {
/** /**
* Current request * Current request
* *
* @var \nre\core\Request * @var Request
*/ */
private $request; private $request;
/** /**
* Construct a new linker. * Construct a new linker.
* *
* @param \nre\core\Request $request Current request * @param Request $request Current request
*/ */
function __construct(\nre\requests\WebRequest $request) function __construct(\nre\requests\WebRequest $request)
{ {
$this->request = $request; $this->request = $request;
} }
/** /**
* Mask parameters to be used in an URL. * Mask parameters to be used in an URL.
* *
* @param string $param1 First parameter * @param string $param1 First parameter
* @return string Masked parameters as string * @return string Masked parameters as string
*/ */
public static function createLinkParam($param1) public static function createLinkParam($param1)
{ {
return implode( return implode(
\nre\configs\CoreConfig::$classes['linker']['url']['delimiter'], \nre\configs\CoreConfig::$classes['linker']['url']['delimiter'],
call_user_func_array( call_user_func_array(
'\nre\core\Linker::createLinkParams', '\nre\core\Linker::createLinkParams',
func_get_args() func_get_args()
) )
); );
} }
/** /**
* Mask parameters to be used in an URL. * Mask parameters to be used in an URL.
* *
* @param string $param1 First parameter * @param string $param1 First parameter
* @return string Masked parameters as array * @return string Masked parameters as array
*/ */
public static function createLinkParams($param1) public static function createLinkParams($param1)
{ {
// Parameters // Parameters
$linkParams = array(); $linkParams = array();
$params = func_get_args(); $params = func_get_args();
foreach($params as $param) foreach($params as $param)
{ {
// Delete critical signs // Delete critical signs
$specials = array('/', '?', '&', '#'); $specials = array('/', '?', '&', '#');
foreach($specials as &$special) { foreach($specials as &$special) {
$param = str_replace($special, '', $param); $param = str_replace($special, '', $param);
} }
// Process parameter // Process parameter
$param = str_replace( $param = str_replace(
' ', ' ',
\nre\configs\CoreConfig::$classes['linker']['url']['delimiter'], \nre\configs\CoreConfig::$classes['linker']['url']['delimiter'],
substr( substr(
$param, $param,
0, 0,
\nre\configs\CoreConfig::$classes['linker']['url']['length'] \nre\configs\CoreConfig::$classes['linker']['url']['length']
) )
); );
// Encode parameter // Encode parameter
$linkParams[] = $param; $linkParams[] = $param;
} }
// Return link parameters // Return link parameters
return $linkParams; return $linkParams;
} }
/** /**
* Create a web link. * Create a web link.
* *
* @param array $params Parameters to use * @param array $params Parameters to use
* @param int $offset Ignore first parameters * @param int $offset Ignore first parameters
* @param bool $exclusiveParams Use only the given parameters * @param bool $exclusiveParams Use only the given parameters
* @param array $getParams GET-parameter to use * @param array $getParams GET-parameter to use
* @param bool $exclusiveGetParams Use only the given GET-parameters * @param bool $exclusiveGetParams Use only the given GET-parameters
* @param string $anchor Target anchor * @param string $anchor Target anchor
* @param bool $absolute Include hostname etc. for an absolute URL * @param bool $absolute Include hostname etc. for an absolute URL
* @return string Created link * @return string Created link
*/ */
public function link($params=null, $offset=0, $exclusiveParams=true, $getParams=null, $exclusiveGetParams=true, $anchor=null, $absolute=false) public function link($params=null, $offset=0, $exclusiveParams=true, $getParams=null, $exclusiveGetParams=true, $anchor=null, $absolute=false)
{ {
// Make current request to response // Make current request to response
$response = new \nre\responses\WebResponse(); $response = new \nre\responses\WebResponse();
// Check parameters // Check parameters
if(is_null($params)) { if(is_null($params)) {
$params = array(); $params = array();
} }
elseif(!is_array($params)) { elseif(!is_array($params)) {
$params = array($params); $params = array($params);
} }
// Set parameters from request // Set parameters from request
$reqParams = array_slice($this->request->getParams(), 1, $offset); $reqParams = array_slice($this->request->getParams(), 1, $offset);
if(count($reqParams) < $offset && $offset > 0) { if(count($reqParams) < $offset && $offset > 0) {
$reqParams[] = $this->request->getParam(1, 'intermediate'); $reqParams[] = $this->request->getParam(1, 'intermediate');
} }
if(count($reqParams) < $offset && $offset > 1) { if(count($reqParams) < $offset && $offset > 1) {
$reqParams[] = $this->request->getParam(2, 'action'); $reqParams[] = $this->request->getParam(2, 'action');
} }
$params = array_merge($reqParams, $params); $params = array_merge($reqParams, $params);
// Use Layout // Use Layout
$layout = \nre\configs\AppConfig::$defaults['toplevel']; $layout = \nre\configs\AppConfig::$defaults['toplevel'];
if(!empty($getParams) && array_key_exists('layout', $getParams)) { if(!empty($getParams) && array_key_exists('layout', $getParams)) {
$layout = $getParams['layout']; $layout = $getParams['layout'];
} }
array_unshift($params, $layout); array_unshift($params, $layout);
// Use parameters from request only // Use parameters from request only
if(!$exclusiveParams) if(!$exclusiveParams)
{ {
$params = array_merge( $params = array_merge(
$params, $params,
array_slice( array_slice(
$this->request->getParams(), $this->request->getParams(),
count($params) count($params)
) )
); );
} }
// Encode parameters // Encode parameters
$params = array_map('rawurlencode', $params); $params = array_map('rawurlencode', $params);
// Set parameters // Set parameters
call_user_func_array( call_user_func_array(
array( array(
$response, $response,
'addParams' 'addParams'
), ),
$params $params
); );
// Check GET-parameters // Check GET-parameters
if(is_null($getParams)) { if(is_null($getParams)) {
$getParams = array(); $getParams = array();
} }
elseif(!is_array($params)) { elseif(!is_array($params)) {
$params = array($params); $params = array($params);
} }
if(!$exclusiveGetParams) if(!$exclusiveGetParams)
{ {
$getParams = array_merge( $getParams = array_merge(
$this->request->getGetParams(), $this->request->getGetParams(),
$getParams $getParams
); );
} }
// Set GET-parameters // Set GET-parameters
$response->addGetParams($getParams); $response->addGetParams($getParams);
// Create and return link // Create and return link
return self::createLink($this->request, $response, $anchor, $absolute); return self::createLink($this->request, $response, $anchor, $absolute);
} }
/** /**
* Create a link from an URL. * Create a link from an URL.
* *
* @param string $url URL to create link from * @param string $url URL to create link from
* @param bool $absolute Create absolute URL * @param bool $absolute Create absolute URL
* @return string Created link * @return string Created link
*/ */
public function hardlink($url, $absolute=false) public function hardlink($url, $absolute=false)
{ {
return $this->createUrl($url, $this->request, $absolute); return $this->createUrl($url, $this->request, $absolute);
} }
/** /**
* Create a link. * Create a link.
* *
* @param \nre\core\Request $request Current request * @param Request $request Current request
* @param \nre\core\Response $response Current response * @param Response $response Current response
* @param string $anchor Anchor on target * @param string $anchor Anchor on target
* @param bool $absolute Create absolute link * @param bool $absolute Create absolute link
* @return string Created link * @return string Created link
*/ */
private static function createLink(Request $request, Response $response, $anchor=null, $absolute=false) private static function createLink(Request $request, Response $response, $anchor=null, $absolute=false)
{ {
// Check response // Check response
if(is_null($response)) { if(is_null($response)) {
return null; return null;
} }
// Get parameters // Get parameters
$params = $response->getParams(1); $params = $response->getParams(1);
// Check Action // Check Action
if(count($params) == 2 && $params[1] == \nre\configs\CoreConfig::$defaults['action']) { if(count($params) == 2 && $params[1] == \nre\configs\CoreConfig::$defaults['action']) {
array_pop($params); array_pop($params);
} }
// Set parameters // Set parameters
$link = implode('/', $params); $link = implode('/', $params);
// Apply reverse-routes // Apply reverse-routes
$link = $request->applyReverseRoutes($link); $link = $request->applyReverseRoutes($link);
// Get GET-parameters // Get GET-parameters
$getParams = $response->getGetParams(); $getParams = $response->getGetParams();
// Layout überprüfen // Layout überprüfen
if(array_key_exists('layout', $getParams) && $getParams['layout'] == \nre\configs\AppConfig::$defaults['toplevel']) { if(array_key_exists('layout', $getParams) && $getParams['layout'] == \nre\configs\AppConfig::$defaults['toplevel']) {
unset($getParams['layout']); unset($getParams['layout']);
} }
// Set GET-parameters // Set GET-parameters
if(array_key_exists('url', $getParams)) { if(array_key_exists('url', $getParams)) {
unset($getParams['url']); unset($getParams['url']);
} }
if(count($getParams) > 0) { if(count($getParams) > 0) {
$link .= '?'.http_build_query($getParams); $link .= '?'.http_build_query($getParams);
} }
// Add anchor // Add anchor
if(!is_null($anchor)) { if(!is_null($anchor)) {
$link .= "#$anchor"; $link .= "#$anchor";
} }
// Create URL // Create URL
$url = self::createUrl($link, $request, $absolute); $url = self::createUrl($link, $request, $absolute);
return $url; return $url;
} }
/** /**
* Adapt a link to the environment. * Adapt a link to the environment.
* *
* @param string $url URL * @param string $url URL
* @param \nre\core\Request $request Current request * @param Request $request Current request
* @param bool $absolute Create absolute URL * @param bool $absolute Create absolute URL
* @return string Adapted URL * @return string Adapted URL
*/ */
private static function createUrl($url, Request $request, $absolute=false) private static function createUrl($url, Request $request, $absolute=false)
{ {
// Variables // Variables
$server = $_SERVER['SERVER_NAME']; $server = $_SERVER['SERVER_NAME'];
$uri = $_SERVER['REQUEST_URI']; $uri = $_SERVER['REQUEST_URI'];
$prefix = ''; $prefix = '';
// Determine prefix // Determine prefix
$ppos = array(strlen($uri)); $ppos = array(strlen($uri));
if(($p = strpos($uri, '/'.$request->getParam(1, 'intermediate'))) !== false) { if(($p = strpos($uri, '/'.$request->getParam(1, 'intermediate'))) !== false) {
$ppos[] = $p; $ppos[] = $p;
} }
$prefix = substr($uri, 0, min($ppos)); $prefix = substr($uri, 0, min($ppos));
// Create absolute URL // Create absolute URL
if($absolute) { if($absolute) {
$prefix = "http://$server/".trim($prefix, '/'); $prefix = "http://$server/".trim($prefix, '/');
} }
// Put URL together // Put URL together
$url = rtrim($prefix, '/').'/'.ltrim($url, '/'); $url = rtrim($prefix, '/').'/'.ltrim($url, '/');
// Return URL // Return URL
return $url; return $url;
} }
} }
?> ?>

View file

@ -1,143 +1,143 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Class to log messages to different targets. * Class to log messages to different targets.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class Logger class Logger
{ {
/** /**
* Log mode: Detect automatic * Log mode: Detect automatic
* *
* @var int * @var int
*/ */
const LOGMODE_AUTO = 0; const LOGMODE_AUTO = 0;
/** /**
* Log mode: Print to screen * Log mode: Print to screen
* *
* @var int * @var int
*/ */
const LOGMODE_SCREEN = 1; const LOGMODE_SCREEN = 1;
/** /**
* Log mode: Use PHP-logging mechanism * Log mode: Use PHP-logging mechanism
* *
* @var int * @var int
*/ */
const LOGMODE_PHP = 2; const LOGMODE_PHP = 2;
/** /**
* Do not auto-log to screen * Do not auto-log to screen
* *
* @var boolean * @var boolean
*/ */
private $autoLogToScreenDisabled = false; private $autoLogToScreenDisabled = false;
/** /**
* Construct a new logger. * Construct a new logger.
*/ */
public function __construct() public function __construct()
{ {
} }
/** /**
* Log a message. * Log a message.
* *
* @param string $message Message to log * @param string $message Message to log
* @param int $logMode Log mode to use * @param int $logMode Log mode to use
*/ */
public function log($message, $logMode=self::LOGMODE_SCREEN) public function log($message, $logMode=self::LOGMODE_SCREEN)
{ {
// Choose log mode automatically // Choose log mode automatically
if($logMode == self::LOGMODE_AUTO) { if($logMode == self::LOGMODE_AUTO) {
$logMode = $this->getAutoLogMode(); $logMode = $this->getAutoLogMode();
} }
// Print message to screen // Print message to screen
if($logMode & self::LOGMODE_SCREEN) { if($logMode & self::LOGMODE_SCREEN) {
$this->logToScreen($message); $this->logToScreen($message);
} }
// Use PHP-logging mechanism // Use PHP-logging mechanism
if($logMode & self::LOGMODE_PHP) { if($logMode & self::LOGMODE_PHP) {
$this->logToPhp($message); $this->logToPhp($message);
} }
} }
/** /**
* Disable logging to screen when the log mode is automatically * Disable logging to screen when the log mode is automatically
* detected. * detected.
*/ */
public function disableAutoLogToScreen() public function disableAutoLogToScreen()
{ {
$this->autoLogToScreenDisabled = true; $this->autoLogToScreenDisabled = true;
} }
/** /**
* Print a message to screen. * Print a message to screen.
* *
* @param string $message Message to print * @param string $message Message to print
*/ */
private function logToScreen($message) private function logToScreen($message)
{ {
echo "$message<br>\n"; echo "$message<br>\n";
} }
/** /**
* Log a message by using PHP-logging mechanism. * Log a message by using PHP-logging mechanism.
* *
* @param string $message Message to log * @param string $message Message to log
*/ */
private function logToPhp($message) private function logToPhp($message)
{ {
error_log($message, 0); error_log($message, 0);
} }
/** /**
* Detect log mode automatically by distinguishing between * Detect log mode automatically by distinguishing between
* production and test environment. * production and test environment.
* *
* @return int Automatically detected log mode * @return int Automatically detected log mode
*/ */
private function getAutoLogMode() private function getAutoLogMode()
{ {
return ($this->isLocalhost() && !$this->autoLogToScreenDisabled) ? self::LOGMODE_SCREEN : self::LOGMODE_PHP; return ($this->isLocalhost() && !$this->autoLogToScreenDisabled) ? self::LOGMODE_SCREEN : self::LOGMODE_PHP;
} }
/** /**
* Detect if the server is running as localhost without domain. * Detect if the server is running as localhost without domain.
* *
* @return boolean Wheather server is running as localhost or not * @return boolean Wheather server is running as localhost or not
*/ */
private function isLocalhost() private function isLocalhost()
{ {
return ($_SERVER['SERVER_ADDR'] == '127.0.0.1' || $_SERVER['SERVER_ADDR'] = '::1'); return ($_SERVER['SERVER_ADDR'] == '127.0.0.1' || $_SERVER['SERVER_ADDR'] = '::1');
} }
} }
?> ?>

View file

@ -1,141 +1,141 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Abstract class for implementing a Model. * Abstract class for implementing a Model.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
abstract class Model abstract class Model
{ {
/** /**
* Load the class of a Model. * Load the class of a Model.
* *
* @throws \nre\exceptions\ModelNotFoundException * @throws \nre\exceptions\ModelNotFoundException
* @throws \nre\exceptions\ModelNotValidException * @throws \nre\exceptions\ModelNotValidException
* @param string $modelName Name of the Model to load * @param string $modelName Name of the Model to load
*/ */
public static function load($modelName) public static function load($modelName)
{ {
// Determine full classname // Determine full classname
$className = self::getClassName($modelName); $className = self::getClassName($modelName);
try { try {
// Load class // Load class
ClassLoader::load($className); ClassLoader::load($className);
// Validate class // Validate class
ClassLoader::check($className, get_class()); ClassLoader::check($className, get_class());
} }
catch(\nre\exceptions\ClassNotValidException $e) { catch(\nre\exceptions\ClassNotValidException $e) {
throw new \nre\exceptions\ModelNotValidException($e->getClassName()); throw new \nre\exceptions\ModelNotValidException($e->getClassName());
} }
catch(\nre\exceptions\ClassNotFoundException $e) { catch(\nre\exceptions\ClassNotFoundException $e) {
throw new \nre\exceptions\ModelNotFoundException($e->getClassName()); throw new \nre\exceptions\ModelNotFoundException($e->getClassName());
} }
} }
/** /**
* Instantiate a Model (Factory Pattern). * Instantiate a Model (Factory Pattern).
* *
* @param string $modelName Name of the Model to instantiate * @param string $modelName Name of the Model to instantiate
*/ */
public static function factory($modelName) public static function factory($modelName)
{ {
// Determine full classname // Determine full classname
$className = self::getClassName($modelName); $className = self::getClassName($modelName);
// Construct and return Model // Construct and return Model
return new $className(); return new $className();
} }
/** /**
* Determine the classname for the given Model name. * Determine the classname for the given Model name.
* *
* @param string $modelName Model name to get classname of * @param string $modelName Model name to get classname of
* @return string Classname fore the Model name * @return string Classname fore the Model name
*/ */
private static function getClassName($modelName) private static function getClassName($modelName)
{ {
$className = ClassLoader::concatClassNames($modelName, ClassLoader::stripNamespace(get_class())); $className = ClassLoader::concatClassNames($modelName, ClassLoader::stripNamespace(get_class()));
return \nre\configs\AppConfig::$app['namespace']."models\\$className"; return \nre\configs\AppConfig::$app['namespace']."models\\$className";
} }
/** /**
* Construct a new Model. * Construct a new Model.
* *
* TODO Catch exception * TODO Catch exception
* *
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @throws \nre\exceptions\DriverNotFoundException * @throws \nre\exceptions\DriverNotFoundException
* @throws \nre\exceptions\DriverNotValidException * @throws \nre\exceptions\DriverNotValidException
* @throws \nre\exceptions\ModelNotValidException * @throws \nre\exceptions\ModelNotValidException
* @throws \nre\exceptions\ModelNotFoundException * @throws \nre\exceptions\ModelNotFoundException
*/ */
protected function __construct() protected function __construct()
{ {
// Load Models // Load Models
$this->loadModels(); $this->loadModels();
} }
/** /**
* Load the Models of this Model. * Load the Models of this Model.
* *
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @throws \nre\exceptions\DriverNotFoundException * @throws \nre\exceptions\DriverNotFoundException
* @throws \nre\exceptions\DriverNotValidException * @throws \nre\exceptions\DriverNotValidException
* @throws \nre\exceptions\ModelNotValidException * @throws \nre\exceptions\ModelNotValidException
* @throws \nre\exceptions\ModelNotFoundException * @throws \nre\exceptions\ModelNotFoundException
*/ */
private function loadModels() private function loadModels()
{ {
// Determine Models // Determine Models
$models = array(); $models = array();
if(property_exists($this, 'models')) { if(property_exists($this, 'models')) {
$models = $this->models; $models = $this->models;
} }
if(!is_array($models)) { if(!is_array($models)) {
$models = array($models); $models = array($models);
} }
// Load Models // Load Models
foreach($models as $model) foreach($models as $model)
{ {
// Load class // Load class
Model::load($model); Model::load($model);
// Construct Model // Construct Model
$modelName = ucfirst(strtolower($model)); $modelName = ucfirst(strtolower($model));
$this->$modelName = Model::factory($model); $this->$modelName = Model::factory($model);
} }
} }
} }
?> ?>

View file

@ -1,64 +1,64 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Base class to represent a request. * Base class to represent a request.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class Request class Request
{ {
/** /**
* Passed parameters * Passed parameters
* *
* @var array * @var array
*/ */
protected $params = array(); protected $params = array();
/** /**
* Get a parameter. * Get a parameter.
* *
* @param int $index Index of parameter * @param int $index Index of parameter
* @param string $defaultIndex Index of default configuration value for this parameter * @param string $defaultIndex Index of default configuration value for this parameter
* @return string Value of parameter * @return string Value of parameter
*/ */
public function getParam($index, $defaultIndex=null) public function getParam($index, $defaultIndex=null)
{ {
// Return parameter // Return parameter
if(count($this->params) > $index) { if(count($this->params) > $index) {
return $this->params[$index]; return $this->params[$index];
} }
// Return default value // Return default value
return \nre\core\Config::getDefault($defaultIndex); return \nre\core\Config::getDefault($defaultIndex);
} }
/** /**
* Get all parameters from index on. * Get all parameters from index on.
* *
* @param int $offset Offset-index * @param int $offset Offset-index
* @return array Parameter values * @return array Parameter values
*/ */
public function getParams($offset=0) public function getParams($offset=0)
{ {
return array_slice($this->params, $offset); return array_slice($this->params, $offset);
} }
} }
?> ?>

View file

@ -1,158 +1,158 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Base class to represent a response. * Base class to represent a response.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class Response class Response
{ {
/** /**
* Applied parameters * Applied parameters
* *
* @var array * @var array
*/ */
protected $params = array(); protected $params = array();
/** /**
* Generated output * Generated output
* *
* @var string * @var string
*/ */
private $output = ''; private $output = '';
/** /**
* Abort futher execution * Abort futher execution
* *
* @var bool * @var bool
*/ */
private $exit = false; private $exit = false;
/** /**
* Add a parameter. * Add a parameter.
* *
* @param mixed $value Value of parameter * @param mixed $value Value of parameter
*/ */
public function addParam($value) public function addParam($value)
{ {
$this->params[] = $value; $this->params[] = $value;
} }
/** /**
* Add multiple parameters. * Add multiple parameters.
* *
* @param mixed $value1 Value of first parameter * @param mixed $value1 Value of first parameter
* @param mixed Values of further parameters * @param mixed Values of further parameters
*/ */
public function addParams($value1) public function addParams($value1)
{ {
$this->params = array_merge( $this->params = array_merge(
$this->params, $this->params,
func_get_args() func_get_args()
); );
} }
/** /**
* Delete all stored parameters (from offset on). * Delete all stored parameters (from offset on).
* *
* @param int $offset Offset-index * @param int $offset Offset-index
*/ */
public function clearParams($offset=0) public function clearParams($offset=0)
{ {
$this->params = array_slice($this->params, 0, $offset); $this->params = array_slice($this->params, 0, $offset);
} }
/** /**
* Get a parameter. * Get a parameter.
* *
* @param int $index Index of parameter * @param int $index Index of parameter
* @param string $defaultIndex Index of default configuration value for this parameter * @param string $defaultIndex Index of default configuration value for this parameter
* @return string Value of parameter * @return string Value of parameter
*/ */
public function getParam($index, $defaultIndex=null) public function getParam($index, $defaultIndex=null)
{ {
// Return parameter // Return parameter
if(count($this->params) > $index) { if(count($this->params) > $index) {
return $this->params[$index]; return $this->params[$index];
} }
// Return default value // Return default value
return \nre\core\Config::getDefault($defaultIndex); return \nre\core\Config::getDefault($defaultIndex);
} }
/** /**
* Get all parameters from index on. * Get all parameters from index on.
* *
* @param int $offset Offset-index * @param int $offset Offset-index
* @return array Parameter values * @return array Parameter values
*/ */
public function getParams($offset=0) public function getParams($offset=0)
{ {
return array_slice($this->params, $offset); return array_slice($this->params, $offset);
} }
/** /**
* Set output. * Set output.
* *
* @param string $output Generated output * @param string $output Generated output
*/ */
public function setOutput($output) public function setOutput($output)
{ {
$this->output = $output; $this->output = $output;
} }
/** /**
* Get generated output. * Get generated output.
* *
* @return string Generated output * @return string Generated output
*/ */
public function getOutput() public function getOutput()
{ {
return $this->output; return $this->output;
} }
/** /**
* Set exit-state. * Set exit-state.
* *
* @param bool $exit Abort further execution * @param bool $exit Abort further execution
*/ */
public function setExit($exit=true) public function setExit($exit=true)
{ {
$this->exit = $exit; $this->exit = $exit;
} }
/** /**
* Get exit-state. * Get exit-state.
* *
* @return bool Abort further execution * @return bool Abort further execution
*/ */
public function getExit() public function getExit()
{ {
return $this->exit; return $this->exit;
} }
} }
?> ?>

View file

@ -1,124 +1,124 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* View. * View.
* *
* Class to encapsulate a template file and to provide rendering methods. * Class to encapsulate a template file and to provide rendering methods.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class View class View
{ {
/** /**
* Template filename * Template filename
* *
* @var string * @var string
*/ */
protected $templateFilename; protected $templateFilename;
/** /**
* Load and instantiate the View of an Agent. * Load and instantiate the View of an Agent.
* *
* @throws \nre\exceptions\ViewNotFoundException * @throws \nre\exceptions\ViewNotFoundException
* @param string $layoutName Name of Layout in use * @param string $layoutName Name of Layout in use
* @param string $agentName Name of the Agent * @param string $agentName Name of the Agent
* @param string $action Current Action * @param string $action Current Action
* @param bool $isToplevel Agent is a ToplevelAgent * @param bool $isToplevel Agent is a ToplevelAgent
*/ */
public static function loadAndFactory($layoutName, $agentName=null, $action=null, $isToplevel=false) public static function loadAndFactory($layoutName, $agentName=null, $action=null, $isToplevel=false)
{ {
return new View($layoutName, $agentName, $action, $isToplevel); return new View($layoutName, $agentName, $action, $isToplevel);
} }
/** /**
* Construct a new View. * Construct a new View.
* *
* @throws \nre\exceptions\ViewNotFoundException * @throws \nre\exceptions\ViewNotFoundException
* @param string $layoutName Name of Layout in use * @param string $layoutName Name of Layout in use
* @param string $agentName Name of the Agent * @param string $agentName Name of the Agent
* @param string $action Current Action * @param string $action Current Action
* @param bool $isToplevel Agent is a ToplevelAgent * @param bool $isToplevel Agent is a ToplevelAgent
*/ */
protected function __construct($layoutName, $agentName=null, $action=null, $isToplevel=false) protected function __construct($layoutName, $agentName=null, $action=null, $isToplevel=false)
{ {
// Create template filename // Create template filename
// LayoutName // LayoutName
$fileName = ROOT.DS. \nre\configs\CoreConfig::getClassDir('views').DS. strtolower($layoutName).DS; $fileName = ROOT.DS. \nre\configs\CoreConfig::getClassDir('views').DS. strtolower($layoutName).DS;
// AgentName and Action // AgentName and Action
if(strtolower($agentName) != strtolower($layoutName) || !$isToplevel) { if(strtolower($agentName) != strtolower($layoutName) || !$isToplevel) {
$fileName .= strtolower($agentName).DS.strtolower($action); $fileName .= strtolower($agentName).DS.strtolower($action);
} }
else { else {
$fileName .= strtolower($layoutName); $fileName .= strtolower($layoutName);
} }
// File extension // File extension
$fileName .= \nre\configs\CoreConfig::getFileExt('views'); $fileName .= \nre\configs\CoreConfig::getFileExt('views');
// Check template file // Check template file
if(!file_exists($fileName)) { if(!file_exists($fileName)) {
throw new \nre\exceptions\ViewNotFoundException($fileName); throw new \nre\exceptions\ViewNotFoundException($fileName);
} }
// Save filename // Save filename
$this->templateFilename = $fileName; $this->templateFilename = $fileName;
} }
/** /**
* Generate output * Generate output
* *
* @param array $data Data to have available in the template file * @param array $data Data to have available in the template file
*/ */
public function render($data) public function render($data)
{ {
// Extract data // Extract data
if(!is_null($data)) { if(!is_null($data)) {
extract($data, EXTR_SKIP); extract($data, EXTR_SKIP);
} }
// Buffer output // Buffer output
ob_start(); ob_start();
// Include template // Include template
include($this->templateFilename); include($this->templateFilename);
// Return buffered output // Return buffered output
return ob_get_clean(); return ob_get_clean();
} }
/** /**
* Get template filename. * Get template filename.
* *
* @return string Template filename * @return string Template filename
*/ */
public function getTemplateFilename() public function getTemplateFilename()
{ {
return $this->templateFilename; return $this->templateFilename;
} }
} }
?> ?>

View file

@ -1,75 +1,75 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\core; namespace nre\core;
/** /**
* Class that holds several web-specific methods and properties. * Class that holds several web-specific methods and properties.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class WebUtils class WebUtils
{ {
/** /**
* HTTP-statuscode 403: Forbidden * HTTP-statuscode 403: Forbidden
* *
* @var int * @var int
*/ */
const HTTP_FORBIDDEN = 403; const HTTP_FORBIDDEN = 403;
/** /**
* HTTP-statuscode 404: Not Found * HTTP-statuscode 404: Not Found
* *
* @var int * @var int
*/ */
const HTTP_NOT_FOUND = 404; const HTTP_NOT_FOUND = 404;
/** /**
* HTTP-statuscode 503: Service Unavailable * HTTP-statuscode 503: Service Unavailable
* *
* @var int * @var int
*/ */
const HTTP_SERVICE_UNAVAILABLE = 503; const HTTP_SERVICE_UNAVAILABLE = 503;
/** /**
* HTTP-header strings * HTTP-header strings
* *
* @var array * @var array
*/ */
public static $httpStrings = array( public static $httpStrings = array(
200 => 'OK', 200 => 'OK',
304 => 'Not Modified', 304 => 'Not Modified',
403 => 'Forbidden', 403 => 'Forbidden',
404 => 'Not Found', 404 => 'Not Found',
503 => 'Service Unavailable' 503 => 'Service Unavailable'
); );
/** /**
* Get the HTTP-header of a HTTP-statuscode * Get the HTTP-header of a HTTP-statuscode
* *
* @param int $httpStatusCode HTTP-statuscode * @param int $httpStatusCode HTTP-statuscode
* @return string HTTP-header of HTTP-statuscode * @return string HTTP-header of HTTP-statuscode
*/ */
public static function getHttpHeader($httpStatusCode) public static function getHttpHeader($httpStatusCode)
{ {
if(!array_key_exists($httpStatusCode, self::$httpStrings)) { if(!array_key_exists($httpStatusCode, self::$httpStrings)) {
$httpStatusCode = 200; $httpStatusCode = 200;
} }
return sprintf("HTTP/1.1 %d %s\n", $httpStatusCode, self::$httpStrings[$httpStatusCode]); return sprintf("HTTP/1.1 %d %s\n", $httpStatusCode, self::$httpStrings[$httpStatusCode]);
} }
} }
?> ?>

View file

@ -1,87 +1,87 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\drivers; namespace nre\drivers;
/** /**
* Abstract class for implementing a database driver. * Abstract class for implementing a database driver.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
abstract class DatabaseDriver extends \nre\core\Driver abstract class DatabaseDriver extends \nre\core\Driver
{ {
/** /**
* Driver class instance * Driver class instance
* *
* @static * @static
* @var DatabaseDriver * @var DatabaseDriver
*/ */
protected static $driver = null; protected static $driver = null;
/** /**
* Connection resource * Connection resource
* *
* @var resource * @var resource
*/ */
protected $connection = null; protected $connection = null;
/** /**
* Singleton-pattern. * Singleton-pattern.
* *
* @param array $config Database driver configuration * @param array $config Database driver configuration
* @return DatabaseDriver Singleton-instance of database driver class * @return DatabaseDriver Singleton-instance of database driver class
*/ */
public static function singleton($config) public static function singleton($config)
{ {
// Singleton // Singleton
if(self::$driver !== null) { if(self::$driver !== null) {
return self::$driver; return self::$driver;
} }
// Construct // Construct
$className = get_called_class(); $className = get_called_class();
self::$driver = new $className($config); self::$driver = new $className($config);
return self::$driver; return self::$driver;
} }
/** /**
* Construct a new database driver. * Construct a new database driver.
* *
* @param array $config Connection and login settings * @param array $config Connection and login settings
*/ */
protected function __construct($config) protected function __construct($config)
{ {
parent::__construct(); parent::__construct();
// Establish connection // Establish connection
$this->connect($config); $this->connect($config);
} }
/** /**
* Establish a connect to a MqSQL-database. * Establish a connect to a MqSQL-database.
* *
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @param array $config Connection and login settings * @param array $config Connection and login settings
*/ */
protected abstract function connect($config); protected abstract function connect($config);
} }
?> ?>

View file

@ -1,167 +1,167 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\drivers; namespace nre\drivers;
/** /**
* Implementation of a database driver for MySQL-databases. * Implementation of a database driver for MySQL-databases.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class MysqliDriver extends \nre\drivers\DatabaseDriver class MysqliDriver extends \nre\drivers\DatabaseDriver
{ {
/** /**
* Construct a MySQL-driver. * Construct a MySQL-driver.
* *
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @param array $config Connection and login settings * @param array $config Connection and login settings
*/ */
function __construct($config) function __construct($config)
{ {
parent::__construct($config); parent::__construct($config);
} }
/** /**
* Execute a SQL-query. * Execute a SQL-query.
* *
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @param string $query Query to run * @param string $query Query to run
* @param mixed Params * @param mixed Params
* @return array Result * @return array Result
*/ */
public function query($query) public function query($query)
{ {
// Prepare statement // Prepare statement
if(!($stmt = $this->connection->prepare($query))) { if(!($stmt = $this->connection->prepare($query))) {
throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno); throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno);
} }
try { try {
// Prepare data // Prepare data
$data = array(); $data = array();
// Bind parameters // Bind parameters
$p = array_slice(func_get_args(), 1); $p = array_slice(func_get_args(), 1);
$params = array(); $params = array();
foreach($p as $key => $value) { foreach($p as $key => $value) {
$params[$key] = &$p[$key]; $params[$key] = &$p[$key];
} }
if(count($params) > 0) if(count($params) > 0)
{ {
if(!(call_user_func_array(array($stmt, 'bind_param'), $params))) { if(!(call_user_func_array(array($stmt, 'bind_param'), $params))) {
throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno); throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno);
} }
} }
// Execute query // Execute query
if(!$stmt->execute()) { if(!$stmt->execute()) {
throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno); throw new \nre\exceptions\DatamodelException($this->connection->error, $this->connection->errno);
} }
// Fetch result // Fetch result
if($result = $stmt->get_result()) { if($result = $stmt->get_result()) {
while($row = $result->fetch_assoc()) { while($row = $result->fetch_assoc()) {
$data[] = $row; $data[] = $row;
} }
} }
return $data; return $data;
} }
finally { finally {
$stmt->close(); $stmt->close();
} }
} }
/** /**
* Return the last insert id (of the last insert-query). * Return the last insert id (of the last insert-query).
* *
* @return int Last insert id * @return int Last insert id
*/ */
public function getInsertId() public function getInsertId()
{ {
return $this->connection->insert_id; return $this->connection->insert_id;
} }
/** /**
* Enable/disable autocommit feature. * Enable/disable autocommit feature.
* *
* @param boolean $autocommit Enable/disable autocommit * @param boolean $autocommit Enable/disable autocommit
*/ */
public function setAutocommit($autocommit) public function setAutocommit($autocommit)
{ {
$this->connection->autocommit($autocommit); $this->connection->autocommit($autocommit);
} }
/** /**
* Rollback the current transaction. * Rollback the current transaction.
*/ */
public function rollback() public function rollback()
{ {
$this->connection->rollback(); $this->connection->rollback();
} }
/** /**
* Commit the current transaction. * Commit the current transaction.
*/ */
public function commit() public function commit()
{ {
$this->connection->commit(); $this->connection->commit();
} }
/** /**
* Establish a connect to a MqSQL-database. * Establish a connect to a MqSQL-database.
* *
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @param array $config Connection and login settings * @param array $config Connection and login settings
*/ */
protected function connect($config) protected function connect($config)
{ {
// Connect // Connect
$con = @new \mysqli( $con = @new \mysqli(
$config['host'], $config['host'],
$config['user'], $config['user'],
$config['password'], $config['password'],
$config['db'] $config['db']
); );
// Check connection // Check connection
if($con->connect_error) { if($con->connect_error) {
throw new \nre\exceptions\DatamodelException($con->connect_error, $con->connect_errno); throw new \nre\exceptions\DatamodelException($con->connect_error, $con->connect_errno);
} }
// Set character encoding // Set character encoding
if(!$con->set_charset('utf8')) { if(!$con->set_charset('utf8')) {
throw new \nre\exceptions\DatamodelException($con->connect_error, $con->connect_errno); throw new \nre\exceptions\DatamodelException($con->connect_error, $con->connect_errno);
} }
// Save connection // Save connection
$this->connection = $con; $this->connection = $con;
} }
} }
?> ?>

View file

@ -1,51 +1,51 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Access denied. * Exception: Access denied.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class AccessDeniedException extends \nre\core\Exception class AccessDeniedException extends \nre\core\Exception
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 85; const CODE = 85;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'access denied'; const MESSAGE = 'access denied';
/** /**
* Consturct a new exception. * Consturct a new exception.
*/ */
function __construct() function __construct()
{ {
parent::__construct( parent::__construct(
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
} }
?> ?>

View file

@ -1,77 +1,77 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Action not found. * Exception: Action not found.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ActionNotFoundException extends \nre\core\Exception class ActionNotFoundException extends \nre\core\Exception
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 70; const CODE = 70;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'action not found'; const MESSAGE = 'action not found';
/** /**
* Name of the action that was not found * Name of the action that was not found
* *
* @var string * @var string
*/ */
private $action; private $action;
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $action Name of the action that was not found * @param string $action Name of the action that was not found
*/ */
function __construct($action) function __construct($action)
{ {
parent::__construct( parent::__construct(
self::MESSAGE, self::MESSAGE,
self::CODE, self::CODE,
$action $action
); );
// Store values // Store values
$this->action = $action; $this->action = $action;
} }
/** /**
* Get the name of the action that was not found. * Get the name of the action that was not found.
* *
* @return string Name of the action that was not found * @return string Name of the action that was not found
*/ */
public function getAction() public function getAction()
{ {
return $this->action; return $this->action;
} }
} }
?> ?>

View file

@ -1,67 +1,67 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Agent not found. * Exception: Agent not found.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class AgentNotFoundException extends \nre\exceptions\ClassNotFoundException class AgentNotFoundException extends \nre\exceptions\ClassNotFoundException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 66; const CODE = 66;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'agent not found'; const MESSAGE = 'agent not found';
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $agentName Name of the Agent that was not found * @param string $agentName Name of the Agent that was not found
*/ */
function __construct($agentName) function __construct($agentName)
{ {
parent::__construct( parent::__construct(
$agentName, $agentName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the Agent that was not found. * Get the name of the Agent that was not found.
* *
* @return string Name of the Agent that was not found * @return string Name of the Agent that was not found
*/ */
public function getAgentName() public function getAgentName()
{ {
return $this->getClassName(); return $this->getClassName();
} }
} }
?> ?>

View file

@ -1,67 +1,67 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Agent not valid. * Exception: Agent not valid.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class AgentNotValidException extends \nre\exceptions\ClassNotValidException class AgentNotValidException extends \nre\exceptions\ClassNotValidException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 76; const CODE = 76;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'agent not valid'; const MESSAGE = 'agent not valid';
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $agentName Name of the invalid Agent * @param string $agentName Name of the invalid Agent
*/ */
function __construct($agentName) function __construct($agentName)
{ {
parent::__construct( parent::__construct(
$agentName, $agentName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the invalid Agent. * Get the name of the invalid Agent.
* *
* @return string Name of the invalid Agent * @return string Name of the invalid Agent
*/ */
public function getAgentName() public function getAgentName()
{ {
return $this->getClassName(); return $this->getClassName();
} }
} }
?> ?>

View file

@ -1,79 +1,79 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Class not found. * Exception: Class not found.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ClassNotFoundException extends \nre\core\Exception class ClassNotFoundException extends \nre\core\Exception
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 64; const CODE = 64;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'class not found'; const MESSAGE = 'class not found';
/** /**
* Name of the class that was not found * Name of the class that was not found
* *
* @var string * @var string
*/ */
private $className; private $className;
/** /**
* Construct a new exception * Construct a new exception
* *
* @param string $className Name of the class that was not found * @param string $className Name of the class that was not found
* @param string $message Error message (superclass) * @param string $message Error message (superclass)
* @param int $code Error code (superclass) * @param int $code Error code (superclass)
*/ */
function __construct($className, $message=self::MESSAGE, $code=self::CODE) function __construct($className, $message=self::MESSAGE, $code=self::CODE)
{ {
parent::__construct( parent::__construct(
$message, $message,
$code, $code,
$className $className
); );
// Store values // Store values
$this->className = $className; $this->className = $className;
} }
/** /**
* Get the name of the class that was not found. * Get the name of the class that was not found.
* *
* @return string Name of the class that was not found * @return string Name of the class that was not found
*/ */
public function getClassName() public function getClassName()
{ {
return $this->className; return $this->className;
} }
} }
?> ?>

View file

@ -1,79 +1,79 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Class not valid. * Exception: Class not valid.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ClassNotValidException extends \nre\core\Exception class ClassNotValidException extends \nre\core\Exception
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 74; const CODE = 74;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'class not valid'; const MESSAGE = 'class not valid';
/** /**
* Name of the invalid class * Name of the invalid class
* *
* @var string * @var string
*/ */
private $className; private $className;
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $className Name of the invalid class * @param string $className Name of the invalid class
* @param string $message Error message (superclass) * @param string $message Error message (superclass)
* @param int $code Error code (superclass) * @param int $code Error code (superclass)
*/ */
function __construct($className, $message=self::MESSAGE, $code=self::CODE) function __construct($className, $message=self::MESSAGE, $code=self::CODE)
{ {
parent::__construct( parent::__construct(
$message, $message,
$code, $code,
$className $className
); );
// Store value // Store value
$this->className = $className; $this->className = $className;
} }
/** /**
* Get the name of the invalid class. * Get the name of the invalid class.
* *
* @return string Name of the invalid class * @return string Name of the invalid class
*/ */
public function getClassName() public function getClassName()
{ {
return $this->className; return $this->className;
} }
} }
?> ?>

View file

@ -1,67 +1,67 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Component not found. * Exception: Component not found.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ComponentNotFoundException extends \nre\exceptions\ClassNotFoundException class ComponentNotFoundException extends \nre\exceptions\ClassNotFoundException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 67; const CODE = 67;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'component not found'; const MESSAGE = 'component not found';
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $componentName Name of the Component that was not found * @param string $componentName Name of the Component that was not found
*/ */
function __construct($componentName) function __construct($componentName)
{ {
parent::__construct( parent::__construct(
$componentName, $componentName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the Component that was not found. * Get the name of the Component that was not found.
* *
* @return string Name of the Component that was not found * @return string Name of the Component that was not found
*/ */
public function getComponentName() public function getComponentName()
{ {
return $this->getClassName(); return $this->getClassName();
} }
} }
?> ?>

View file

@ -1,67 +1,67 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Component not valid. * Exception: Component not valid.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ComponentNotValidException extends \nre\exceptions\ClassNotValidException class ComponentNotValidException extends \nre\exceptions\ClassNotValidException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 77; const CODE = 77;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'component not valid'; const MESSAGE = 'component not valid';
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $componentName Name of the invalid Component * @param string $componentName Name of the invalid Component
*/ */
function __construct($componentName) function __construct($componentName)
{ {
parent::__construct( parent::__construct(
$componentName, $componentName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the invalid Component. * Get the name of the invalid Component.
* *
* @return string Name of the invalid Component * @return string Name of the invalid Component
*/ */
public function getComponentName() public function getComponentName()
{ {
return $this->getClassName(); return $this->getClassName();
} }
} }
?> ?>

View file

@ -1,67 +1,67 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Controller not found. * Exception: Controller not found.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ControllerNotFoundException extends \nre\exceptions\ClassNotFoundException class ControllerNotFoundException extends \nre\exceptions\ClassNotFoundException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 67; const CODE = 67;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'controller not found'; const MESSAGE = 'controller not found';
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $controllerName Name of the Controller that was not found * @param string $controllerName Name of the Controller that was not found
*/ */
function __construct($controllerName) function __construct($controllerName)
{ {
parent::__construct( parent::__construct(
$controllerName, $controllerName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the Controller that was not found. * Get the name of the Controller that was not found.
* *
* @return string Name of the Controller that was not found * @return string Name of the Controller that was not found
*/ */
public function getControllerName() public function getControllerName()
{ {
return $this->getClassName(); return $this->getClassName();
} }
} }
?> ?>

View file

@ -1,67 +1,67 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Controller not valid. * Exception: Controller not valid.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ControllerNotValidException extends \nre\exceptions\ClassNotValidException class ControllerNotValidException extends \nre\exceptions\ClassNotValidException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 77; const CODE = 77;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'controller not valid'; const MESSAGE = 'controller not valid';
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $controllerName Name of the invalid Controller * @param string $controllerName Name of the invalid Controller
*/ */
function __construct($controllerName) function __construct($controllerName)
{ {
parent::__construct( parent::__construct(
$controllerName, $controllerName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the invalid Controller. * Get the name of the invalid Controller.
* *
* @return string Name of the invalid Controller * @return string Name of the invalid Controller
*/ */
public function getControllerName() public function getControllerName()
{ {
return $this->getClassName(); return $this->getClassName();
} }
} }
?> ?>

View file

@ -1,99 +1,99 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Datamodel. * Exception: Datamodel.
* *
* This exception is thrown when an error occurred during the execution * This exception is thrown when an error occurred during the execution
* of a datamodel. * of a datamodel.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class DatamodelException extends \nre\core\Exception class DatamodelException extends \nre\core\Exception
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 84; const CODE = 84;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'datamodel error'; const MESSAGE = 'datamodel error';
/** /**
* Error message of datamodel * Error message of datamodel
* *
* @var string * @var string
*/ */
private $datamodelMessage; private $datamodelMessage;
/** /**
* Error code of datamodel * Error code of datamodel
* *
* @var int * @var int
*/ */
private $datamodelErrorNumber; private $datamodelErrorNumber;
/** /**
* Consturct a new exception. * Consturct a new exception.
* *
* @param string $datamodelMessage Error message of datamodel * @param string $datamodelMessage Error message of datamodel
* @param int $datamodelErrorNumber Error code of datamodel * @param int $datamodelErrorNumber Error code of datamodel
*/ */
function __construct($datamodelMessage, $datamodelErrorNumber) function __construct($datamodelMessage, $datamodelErrorNumber)
{ {
parent::__construct( parent::__construct(
self::MESSAGE, self::MESSAGE,
self::CODE, self::CODE,
$datamodelMessage." ($datamodelErrorNumber)" $datamodelMessage." ($datamodelErrorNumber)"
); );
// Store values // Store values
$this->datamodelMessage = $datamodelMessage; $this->datamodelMessage = $datamodelMessage;
$this->datamodelErrorNumber = $datamodelErrorNumber; $this->datamodelErrorNumber = $datamodelErrorNumber;
} }
/** /**
* Get the error message of datamodel. * Get the error message of datamodel.
* *
* @return string Error message of datamodel * @return string Error message of datamodel
*/ */
public function getDatamodelMessage() public function getDatamodelMessage()
{ {
return $this->datamodelMessage; return $this->datamodelMessage;
} }
/** /**
* Get the error code of datamodel. * Get the error code of datamodel.
* *
* @return string Error code of datamodel * @return string Error code of datamodel
*/ */
public function getDatamodelErrorNumber() public function getDatamodelErrorNumber()
{ {
return $this->datamodelErrorNumber; return $this->datamodelErrorNumber;
} }
} }
?> ?>

View file

@ -1,68 +1,68 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Driver not found. * Exception: Driver not found.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class DriverNotFoundException extends \nre\exceptions\ClassNotFoundException class DriverNotFoundException extends \nre\exceptions\ClassNotFoundException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 71; const CODE = 71;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'driver not found'; const MESSAGE = 'driver not found';
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $driverName Name of the driver that was not found * @param string $driverName Name of the driver that was not found
*/ */
function __construct($driverName) function __construct($driverName)
{ {
// Elternkonstruktor aufrufen // Elternkonstruktor aufrufen
parent::__construct( parent::__construct(
$driverName, $driverName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the driver that was not found. * Get the name of the driver that was not found.
* *
* @return string Name of the driver that was not found * @return string Name of the driver that was not found
*/ */
public function getDriverName() public function getDriverName()
{ {
return $this->getClassName(); return $this->getClassName();
} }
} }
?> ?>

View file

@ -1,68 +1,68 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Driver not valid. * Exception: Driver not valid.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class DriverNotValidException extends \nre\exceptions\ClassNotValidException class DriverNotValidException extends \nre\exceptions\ClassNotValidException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 81; const CODE = 81;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'driver not valid'; const MESSAGE = 'driver not valid';
/** /**
* Konstruktor. * Konstruktor.
* *
* @param string $driverName Name of the invalid driver * @param string $driverName Name of the invalid driver
*/ */
function __construct($driverName) function __construct($driverName)
{ {
// Elternkonstruktor aufrufen // Elternkonstruktor aufrufen
parent::__construct( parent::__construct(
$driverName, $driverName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the invalid driver. * Get the name of the invalid driver.
* *
* @return string Name of the invalid driver * @return string Name of the invalid driver
*/ */
public function getDriverName() public function getDriverName()
{ {
return $this->getClassName(); return $this->getClassName();
} }
} }
?> ?>

View file

@ -1,96 +1,96 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Datamodel exception that is fatal for the application. * Exception: Datamodel exception that is fatal for the application.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class FatalDatamodelException extends \nre\core\Exception class FatalDatamodelException extends \nre\core\Exception
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 85; const CODE = 85;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'fatal datamodel error'; const MESSAGE = 'fatal datamodel error';
/** /**
* Error message of datamodel * Error message of datamodel
* *
* @var string * @var string
*/ */
private $datamodelMessage; private $datamodelMessage;
/** /**
* Error code of datamodel * Error code of datamodel
* *
* @var int * @var int
*/ */
private $datamodelErrorNumber; private $datamodelErrorNumber;
/** /**
* Consturct a new exception. * Consturct a new exception.
* *
* @param string $datamodelMessage Error message of datamodel * @param string $datamodelMessage Error message of datamodel
* @param int $datamodelErrorNumber Error code of datamodel * @param int $datamodelErrorNumber Error code of datamodel
*/ */
function __construct($datamodelMessage, $datamodelErrorNumber) function __construct($datamodelMessage, $datamodelErrorNumber)
{ {
parent::__construct( parent::__construct(
self::MESSAGE, self::MESSAGE,
self::CODE, self::CODE,
$datamodelMessage." ($datamodelErrorNumber)" $datamodelMessage." ($datamodelErrorNumber)"
); );
// Store values // Store values
$this->datamodelMessage = $datamodelMessage; $this->datamodelMessage = $datamodelMessage;
$this->datamodelErrorNumber = $datamodelErrorNumber; $this->datamodelErrorNumber = $datamodelErrorNumber;
} }
/** /**
* Get the error message of datamodel. * Get the error message of datamodel.
* *
* @return string Error message of datamodel * @return string Error message of datamodel
*/ */
public function getDatamodelMessage() public function getDatamodelMessage()
{ {
return $this->datamodelMessage; return $this->datamodelMessage;
} }
/** /**
* Get the error code of datamodel. * Get the error code of datamodel.
* *
* @return string Error code of datamodel * @return string Error code of datamodel
*/ */
public function getDatamodelErrorNumber() public function getDatamodelErrorNumber()
{ {
return $this->datamodelErrorNumber; return $this->datamodelErrorNumber;
} }
} }
?> ?>

View file

@ -1,77 +1,77 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: ID not found. * Exception: ID not found.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class IdNotFoundException extends \nre\core\Exception class IdNotFoundException extends \nre\core\Exception
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 85; const CODE = 85;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'id not found'; const MESSAGE = 'id not found';
/** /**
* ID that was not found * ID that was not found
* *
* @var mixed * @var mixed
*/ */
private $id; private $id;
/** /**
* Consturct a new exception. * Consturct a new exception.
* *
* @param mixed $id ID that was not found * @param mixed $id ID that was not found
*/ */
function __construct($id) function __construct($id)
{ {
parent::__construct( parent::__construct(
self::MESSAGE, self::MESSAGE,
self::CODE, self::CODE,
$id $id
); );
// Store values // Store values
$this->id = $id; $this->id = $id;
} }
/** /**
* Get the ID that was not found. * Get the ID that was not found.
* *
* @return mixed ID that was not found * @return mixed ID that was not found
*/ */
public function getId() public function getId()
{ {
return $this->id; return $this->id;
} }
} }
?> ?>

View file

@ -1,68 +1,68 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Layout not found. * Exception: Layout not found.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class LayoutNotFoundException extends \nre\exceptions\AgentNotFoundException class LayoutNotFoundException extends \nre\exceptions\AgentNotFoundException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 65; const CODE = 65;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'layout not found'; const MESSAGE = 'layout not found';
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $layoutName Name of the Layout that was not found * @param string $layoutName Name of the Layout that was not found
*/ */
function __construct($layoutName) function __construct($layoutName)
{ {
// Elternkonstruktor aufrufen // Elternkonstruktor aufrufen
parent::__construct( parent::__construct(
$layoutName, $layoutName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the Layout that was not found. * Get the name of the Layout that was not found.
* *
* @return string Name of the Layout that was not found * @return string Name of the Layout that was not found
*/ */
public function getLayoutName() public function getLayoutName()
{ {
return $this->getAgentName(); return $this->getAgentName();
} }
} }
?> ?>

View file

@ -1,67 +1,67 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Layout not valid. * Exception: Layout not valid.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class LayoutNotValidException extends \nre\exceptions\AgentNotFoundException class LayoutNotValidException extends \nre\exceptions\AgentNotFoundException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 75; const CODE = 75;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'layout not valid'; const MESSAGE = 'layout not valid';
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $layoutName Name of the invalid Layout * @param string $layoutName Name of the invalid Layout
*/ */
function __construct($layoutName) function __construct($layoutName)
{ {
parent::__construct( parent::__construct(
$layoutName, $layoutName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the invalid Layout. * Get the name of the invalid Layout.
* *
* @return string Name of the invalid Layout * @return string Name of the invalid Layout
*/ */
public function getLayoutName() public function getLayoutName()
{ {
return $this->getAgentName(); return $this->getAgentName();
} }
} }
?> ?>

View file

@ -1,67 +1,67 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Action not found. * Exception: Action not found.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ModelNotFoundException extends \nre\exceptions\ClassNotFoundException class ModelNotFoundException extends \nre\exceptions\ClassNotFoundException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 68; const CODE = 68;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'model not found'; const MESSAGE = 'model not found';
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $modelName Name of the Model that was not found * @param string $modelName Name of the Model that was not found
*/ */
function __construct($modelName) function __construct($modelName)
{ {
parent::__construct( parent::__construct(
$modelName, $modelName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the Model that was not found * Get the name of the Model that was not found
* *
* @return string Name of the Model that was not found * @return string Name of the Model that was not found
*/ */
public function getModelName() public function getModelName()
{ {
return $this->getClassName(); return $this->getClassName();
} }
} }
?> ?>

View file

@ -1,68 +1,68 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Action not found. * Exception: Action not found.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ModelNotValidException extends \nre\exceptions\ClassNotValidException class ModelNotValidException extends \nre\exceptions\ClassNotValidException
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 78; const CODE = 78;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'model not valid'; const MESSAGE = 'model not valid';
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $modelName Name of the invalid Model * @param string $modelName Name of the invalid Model
*/ */
function __construct($modelName) function __construct($modelName)
{ {
// Elternkonstruktor aufrufen // Elternkonstruktor aufrufen
parent::__construct( parent::__construct(
$modelName, $modelName,
self::MESSAGE, self::MESSAGE,
self::CODE self::CODE
); );
} }
/** /**
* Get the name of the invalid Model * Get the name of the invalid Model
* *
* @return string Name of the invalid Model * @return string Name of the invalid Model
*/ */
public function getModelName() public function getModelName()
{ {
return $this->getClassName(); return $this->getClassName();
} }
} }
?> ?>

View file

@ -1,77 +1,77 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception Parameters not valid. * Exception Parameters not valid.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ParamsNotValidException extends \nre\core\Exception class ParamsNotValidException extends \nre\core\Exception
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 86; const CODE = 86;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'parameters not valid'; const MESSAGE = 'parameters not valid';
/** /**
* Invalid parameters. * Invalid parameters.
* *
* @var array * @var array
*/ */
private $params; private $params;
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param mixed $param1 Invalid parameters as argument list * @param mixed $param1 Invalid parameters as argument list
*/ */
function __construct($param1) function __construct($param1)
{ {
parent::__construct( parent::__construct(
self::MESSAGE, self::MESSAGE,
self::CODE, self::CODE,
implode(', ', func_get_args()) implode(', ', func_get_args())
); );
// Store values // Store values
$this->params = func_get_args(); $this->params = func_get_args();
} }
/** /**
* Get invalid parameters. * Get invalid parameters.
* *
* @return array Invalid parameters * @return array Invalid parameters
*/ */
public function getParams() public function getParams()
{ {
return $this->params; return $this->params;
} }
} }
?> ?>

View file

@ -1,77 +1,77 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: Service is unavailable. * Exception: Service is unavailable.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ServiceUnavailableException extends \nre\core\Exception class ServiceUnavailableException extends \nre\core\Exception
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 84; const CODE = 84;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'service unavailable'; const MESSAGE = 'service unavailable';
/** /**
* Throws exception * Throws exception
* *
* @var Exception * @var Exception
*/ */
private $exception; private $exception;
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param \Exception $exception Exception that has occurred * @param \Exception $exception Exception that has occurred
*/ */
function __construct($exception) function __construct($exception)
{ {
parent::__construct( parent::__construct(
self::MESSAGE, self::MESSAGE,
self::CODE, self::CODE,
$exception->getMessage() $exception->getMessage()
); );
// Store values // Store values
$this->exception = $exception; $this->exception = $exception;
} }
/** /**
* Get the exception that hat occurred * Get the exception that hat occurred
* *
* @return \Exception Exception that has occurred * @return \Exception Exception that has occurred
*/ */
public function getException() public function getException()
{ {
return $this->exception; return $this->exception;
} }
} }
?> ?>

View file

@ -1,77 +1,77 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\exceptions; namespace nre\exceptions;
/** /**
* Exception: View not found. * Exception: View not found.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class ViewNotFoundException extends \nre\core\Exception class ViewNotFoundException extends \nre\core\Exception
{ {
/** /**
* Error code * Error code
* *
* @var int * @var int
*/ */
const CODE = 69; const CODE = 69;
/** /**
* Error message * Error message
* *
* @var string * @var string
*/ */
const MESSAGE = 'view not found'; const MESSAGE = 'view not found';
/** /**
* Filename of the view that was not found * Filename of the view that was not found
* *
* @var string * @var string
*/ */
private $fileName; private $fileName;
/** /**
* Construct a new exception. * Construct a new exception.
* *
* @param string $fileName Filename of the view that was not found * @param string $fileName Filename of the view that was not found
*/ */
function __construct($fileName) function __construct($fileName)
{ {
parent::__construct( parent::__construct(
self::MESSAGE, self::MESSAGE,
self::CODE, self::CODE,
$fileName $fileName
); );
// Save values // Save values
$this->fileName = $fileName; $this->fileName = $fileName;
} }
/** /**
* Get the filename of the view that was not found. * Get the filename of the view that was not found.
* *
* @return string Filename of the view that was not found * @return string Filename of the view that was not found
*/ */
public function getFileName() public function getFileName()
{ {
return $this->fileName; return $this->fileName;
} }
} }
?> ?>

View file

@ -1,83 +1,83 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\models; namespace nre\models;
/** /**
* Default implementation of a database model. * Default implementation of a database model.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class DatabaseModel extends \nre\core\Model class DatabaseModel extends \nre\core\Model
{ {
/** /**
* Database connection * Database connection
* *
* @static * @static
* @var DatabaseDriver * @var \nre\drivers\DatabaseDriver
*/ */
protected $db = NULL; protected $db = NULL;
/** /**
* Construct a new datamase model. * Construct a new datamase model.
* *
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @throws \nre\exceptions\DriverNotFoundException * @throws \nre\exceptions\DriverNotFoundException
* @throws \nre\exceptions\DriverNotValidException * @throws \nre\exceptions\DriverNotValidException
* @param string $type Database type * @param string $type Database type
* @param array $config Connection settings * @param array $config Connection settings
*/ */
function __construct($type, $config) function __construct($type, $config)
{ {
parent::__construct(); parent::__construct();
// Load database driver // Load database driver
$this->loadDriver($type); $this->loadDriver($type);
// Establish database connection // Establish database connection
$this->connect($type, $config); $this->connect($type, $config);
} }
/** /**
* Load the database driver. * Load the database driver.
* *
* @throws \nre\exceptions\DriverNotFoundException * @throws \nre\exceptions\DriverNotFoundException
* @throws \nre\exceptions\DriverNotValidException * @throws \nre\exceptions\DriverNotValidException
* @param string $driverName Name of the database driver * @param string $driverName Name of the database driver
*/ */
private function loadDriver($driverName) private function loadDriver($driverName)
{ {
\nre\core\Driver::load($driverName); \nre\core\Driver::load($driverName);
} }
/** /**
* Establish a connection to the database. * Establish a connection to the database.
* *
* @throws \nre\exceptions\DatamodelException * @throws \nre\exceptions\DatamodelException
* @param string $driverName Name of the database driver * @param string $driverName Name of the database driver
* @param array $config Connection settings * @param array $config Connection settings
*/ */
private function connect($driverName, $config) private function connect($driverName, $config)
{ {
$this->db = \nre\core\Driver::factory($driverName, $config); $this->db = \nre\core\Driver::factory($driverName, $config);
} }
} }
?> ?>

View file

@ -1,33 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor> <phpdocumentor>
<parser> <parser>
<default-package-name>NRE</default-package-name> <default-package-name>NRE</default-package-name>
<target>doc</target> <target>doc</target>
<markers> <markers>
<item>TODO</item> <item>TODO</item>
</markers> </markers>
<extension>php</extension> <extension>php</extension>
<extension>inc</extension> <extension>inc</extension>
</parser> </parser>
<transformer> <transformer>
<target>doc</target> <target>doc</target>
</transformer> </transformer>
<logging> <logging>
<level>info</level> <level>info</level>
<paths> <paths>
<default>logs/phpdoc.log</default> <default>logs/phpdoc.log</default>
<errors>logs/phpdoc.errors.log</errors> <errors>logs/phpdoc.errors.log</errors>
</paths> </paths>
</logging> </logging>
<files> <files>
<directory>.</directory> <directory>.</directory>
<ignore>doc/*</ignore> <ignore>doc/*</ignore>
<ignore>logs/*</ignore> <ignore>logs/*</ignore>
</files> </files>
<plugins> <plugins>
<plugin path="Core" /> <plugin path="Core" />
</plugins> </plugins>
<transformations> <transformations>
<template name="clean" /> <template name="clean" />
</transformations> </transformations>
</phpdocumentor> </phpdocumentor>

View file

@ -1,401 +1,401 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\requests; namespace nre\requests;
/** /**
* Representation of a web-request. * Representation of a web-request.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class WebRequest extends \nre\core\Request class WebRequest extends \nre\core\Request
{ {
/** /**
* Passed GET-parameters * Passed GET-parameters
* *
* @var array * @var array
*/ */
private $getParams = array(); private $getParams = array();
/** /**
* Passed POST-parameters * Passed POST-parameters
* *
* @var array * @var array
*/ */
private $postParams = array(); private $postParams = array();
/** /**
* Stored routes * Stored routes
* *
* @var array * @var array
*/ */
private $routes = array(); private $routes = array();
/** /**
* Stored reverse-routes * Stored reverse-routes
* *
* @var array * @var array
*/ */
private $reverseRoutes = array(); private $reverseRoutes = array();
/** /**
* Construct a new web-request. * Construct a new web-request.
*/ */
public function __construct() public function __construct()
{ {
// Detect current request // Detect current request
$this->detectRequest(); $this->detectRequest();
// Load GET-parameters // Load GET-parameters
$this->loadGetParams(); $this->loadGetParams();
// Load POST-parameters // Load POST-parameters
$this->loadPostParams(); $this->loadPostParams();
// Detect AJAX // Detect AJAX
$this->detectAJAX(); $this->detectAJAX();
} }
/** /**
* Get a parameter. * Get a parameter.
* *
* @param int $index Index of parameter * @param int $index Index of parameter
* @param string $defaultIndex Index of default configuration value for this parameter * @param string $defaultIndex Index of default configuration value for this parameter
* @return string Value of parameter * @return string Value of parameter
*/ */
public function getParam($index, $defaultIndex=null) public function getParam($index, $defaultIndex=null)
{ {
if($index == 0) { if($index == 0) {
return $this->getGetParam('layout', $defaultIndex); return $this->getGetParam('layout', $defaultIndex);
} }
else { else {
return parent::getParam($index-1, $defaultIndex); return parent::getParam($index-1, $defaultIndex);
} }
} }
/** /**
* Get all parameters from index on. * Get all parameters from index on.
* *
* @param int $offset Offset-index * @param int $offset Offset-index
* @return array Parameters * @return array Parameters
*/ */
public function getParams($offset=0) public function getParams($offset=0)
{ {
if($offset == 0) if($offset == 0)
{ {
return array_merge( return array_merge(
array( array(
$this->getGetParam('layout', 'toplevel') $this->getGetParam('layout', 'toplevel')
), ),
parent::getParams() parent::getParams()
); );
} }
return array_slice($this->params, $offset-1); return array_slice($this->params, $offset-1);
} }
/** /**
* Get a GET-parameter. * Get a GET-parameter.
* *
* @param string $key Key of GET-parameter * @param string $key Key of GET-parameter
* @param string $defaultIndex Index of default configuration value for this parameter * @param string $defaultIndex Index of default configuration value for this parameter
* @return string Value of GET-parameter * @return string Value of GET-parameter
*/ */
public function getGetParam($key, $defaultIndex=null) public function getGetParam($key, $defaultIndex=null)
{ {
// Check key // Check key
if(array_key_exists($key, $this->getParams)) if(array_key_exists($key, $this->getParams))
{ {
// Return value // Return value
return $this->getParams[$key]; return $this->getParams[$key];
} }
// Return default value // Return default value
return \nre\core\Config::getDefault($defaultIndex); return \nre\core\Config::getDefault($defaultIndex);
} }
/** /**
* Get all GET-parameters. * Get all GET-parameters.
* *
* @return array GET-Parameters * @return array GET-Parameters
*/ */
public function getGetParams() public function getGetParams()
{ {
return $this->getParams; return $this->getParams;
} }
/** /**
* Get a POST-parameter. * Get a POST-parameter.
* *
* @param string $key Key of POST-parameter * @param string $key Key of POST-parameter
* @param string $defaultValue Default value for this parameter * @param string $defaultValue Default value for this parameter
* @return string Value of POST-parameter * @return string Value of POST-parameter
*/ */
public function getPostParam($key, $defaultValue=null) public function getPostParam($key, $defaultValue=null)
{ {
// Check key // Check key
if(array_key_exists($key, $this->postParams)) if(array_key_exists($key, $this->postParams))
{ {
// Return value // Return value
return $this->postParams[$key]; return $this->postParams[$key];
} }
// Return default value // Return default value
return $defaultValue; return $defaultValue;
} }
/** /**
* Get all POST-parameters. * Get all POST-parameters.
* *
* @return array POST-parameters * @return array POST-parameters
*/ */
public function getPostParams() public function getPostParams()
{ {
return $this->postParams; return $this->postParams;
} }
/** /**
* Get the method of the current request. * Get the method of the current request.
* *
* @return string Current request method * @return string Current request method
*/ */
public function getRequestMethod() public function getRequestMethod()
{ {
return $_SERVER['REQUEST_METHOD']; return $_SERVER['REQUEST_METHOD'];
} }
/** /**
* Add a URL-route. * Add a URL-route.
* *
* @param string $pattern Regex-Pattern that defines the routing * @param string $pattern Regex-Pattern that defines the routing
* @param string $replacement Regex-Pattern for replacement * @param string $replacement Regex-Pattern for replacement
* @param bool $isLast Stop after that rule * @param bool $isLast Stop after that rule
*/ */
public function addRoute($pattern, $replacement, $isLast=false) public function addRoute($pattern, $replacement, $isLast=false)
{ {
// Store route // Store route
$this->routes[] = $this->newRoute($pattern, $replacement, $isLast); $this->routes[] = $this->newRoute($pattern, $replacement, $isLast);
} }
/** /**
* Add a reverse URL-route. * Add a reverse URL-route.
* *
* @param string $pattern Regex-Pattern that defines the reverse routing * @param string $pattern Regex-Pattern that defines the reverse routing
* @param string $replacement Regex-Pattern for replacement * @param string $replacement Regex-Pattern for replacement
* @param bool $isLast Stop after that rule * @param bool $isLast Stop after that rule
*/ */
public function addReverseRoute($pattern, $replacement, $isLast=false) public function addReverseRoute($pattern, $replacement, $isLast=false)
{ {
// Store reverse route // Store reverse route
$this->reverseRoutes[] = $this->newRoute($pattern, $replacement, $isLast); $this->reverseRoutes[] = $this->newRoute($pattern, $replacement, $isLast);
} }
/** /**
* Apply stored reverse-routes to an URL * Apply stored reverse-routes to an URL
* *
* @param string $url URL to apply reverse-routes to * @param string $url URL to apply reverse-routes to
* @return string Reverse-routed URL * @return string Reverse-routed URL
*/ */
public function applyReverseRoutes($url) public function applyReverseRoutes($url)
{ {
return $this->applyRoutes($url, $this->reverseRoutes); return $this->applyRoutes($url, $this->reverseRoutes);
} }
/** /**
* Revalidate the current request * Revalidate the current request
*/ */
public function revalidate() public function revalidate()
{ {
$this->detectRequest(); $this->detectRequest();
} }
/** /**
* Get a SERVER-parameter. * Get a SERVER-parameter.
* *
* @param string $key Key of SERVER-parameter * @param string $key Key of SERVER-parameter
* @return string Value of SERVER-parameter * @return string Value of SERVER-parameter
*/ */
public function getServerParam($key) public function getServerParam($key)
{ {
if(array_key_exists($key, $_SERVER)) { if(array_key_exists($key, $_SERVER)) {
return $_SERVER[$key]; return $_SERVER[$key];
} }
return null; return null;
} }
/** /**
* Detect the current HTTP-request. * Detect the current HTTP-request.
*/ */
private function detectRequest() private function detectRequest()
{ {
// URL ermitteln // URL ermitteln
$url = isset($_GET) && array_key_exists('url', $_GET) ? $_GET['url'] : ''; $url = isset($_GET) && array_key_exists('url', $_GET) ? $_GET['url'] : '';
$url = trim($url, '/'); $url = trim($url, '/');
// Routes anwenden // Routes anwenden
$url = $this->applyRoutes($url, $this->routes); $url = $this->applyRoutes($url, $this->routes);
// URL splitten // URL splitten
$params = explode('/', $url); $params = explode('/', $url);
if(empty($params[0])) { if(empty($params[0])) {
$params = array(); $params = array();
} }
// Parameter speichern // Parameter speichern
$this->params = $params; $this->params = $params;
} }
/** /**
* Determine parameters passed by GET. * Determine parameters passed by GET.
*/ */
private function loadGetParams() private function loadGetParams()
{ {
if(isset($_GET)) { if(isset($_GET)) {
$this->getParams = $_GET; $this->getParams = $_GET;
} }
} }
/** /**
* Determine parameters passed by POST. * Determine parameters passed by POST.
*/ */
private function loadPostParams() private function loadPostParams()
{ {
if(isset($_POST)) { if(isset($_POST)) {
$this->postParams = $_POST; $this->postParams = $_POST;
} }
} }
/** /**
* Detect an AJAX-request by checking the X-Requested-With * Detect an AJAX-request by checking the X-Requested-With
* header and set the layout to 'ajax' in this case. * header and set the layout to 'ajax' in this case.
*/ */
private function detectAjax() private function detectAjax()
{ {
// Get request headers // Get request headers
$headers = apache_request_headers(); $headers = apache_request_headers();
// Check X-Requested-With header and set layout // Check X-Requested-With header and set layout
if(array_key_exists('X-Requested-With', $headers) && $headers['X-Requested-With'] == 'XMLHttpRequest') { if(array_key_exists('X-Requested-With', $headers) && $headers['X-Requested-With'] == 'XMLHttpRequest') {
if(!array_key_exists('layout', $this->getParams)) { if(!array_key_exists('layout', $this->getParams)) {
$this->getParams['layout'] = 'ajax'; $this->getParams['layout'] = 'ajax';
} }
} }
} }
/** /**
* Create a new URL-route. * Create a new URL-route.
* *
* @param string $pattern Regex-Pattern that defines the reverse routing * @param string $pattern Regex-Pattern that defines the reverse routing
* @param string $replacement Regex-Pattern for replacement * @param string $replacement Regex-Pattern for replacement
* @param bool $isLast Stop after that rule * @param bool $isLast Stop after that rule
* @return array New URL-route * @return array New URL-route
*/ */
private function newRoute($pattern, $replacement, $isLast=false) private function newRoute($pattern, $replacement, $isLast=false)
{ {
return array( return array(
'pattern' => $pattern, 'pattern' => $pattern,
'replacement' => $replacement, 'replacement' => $replacement,
'isLast' => $isLast 'isLast' => $isLast
); );
} }
/** /**
* Apply given routes to an URL * Apply given routes to an URL
* *
* @param string $url URL to apply routes to * @param string $url URL to apply routes to
* @param array $routes Routes to apply * @param array $routes Routes to apply
* @return string Routed URL * @return string Routed URL
*/ */
private function applyRoutes($url, $routes) private function applyRoutes($url, $routes)
{ {
// Traverse given routes // Traverse given routes
foreach($routes as &$route) foreach($routes as &$route)
{ {
// Create and apply Regex // Create and apply Regex
$urlR = preg_replace( $urlR = preg_replace(
'>'.$route['pattern'].'>i', '>'.$route['pattern'].'>i',
$route['replacement'], $route['replacement'],
$url $url
); );
// Split URL // Split URL
$get = ''; $get = '';
if(($gpos = strrpos($urlR, '?')) !== false) { if(($gpos = strrpos($urlR, '?')) !== false) {
$get = substr($urlR, $gpos+1); $get = substr($urlR, $gpos+1);
$urlR = substr($urlR, 0, $gpos); $urlR = substr($urlR, 0, $gpos);
} }
// Has current route changed anything? // Has current route changed anything?
if($urlR != $url || !empty($get)) if($urlR != $url || !empty($get))
{ {
// Extract GET-parameters // Extract GET-parameters
if(strlen($get) > 0) if(strlen($get) > 0)
{ {
$gets = explode('&', $get); $gets = explode('&', $get);
foreach($gets as $get) foreach($gets as $get)
{ {
$get = explode('=', $get); $get = explode('=', $get);
if(!array_key_exists($get[0], $this->getParams)) { if(!array_key_exists($get[0], $this->getParams)) {
$this->getParams[$get[0]] = $get[1]; $this->getParams[$get[0]] = $get[1];
} }
} }
} }
// Stop when route “isLast” // Stop when route “isLast”
if($route['isLast']) { if($route['isLast']) {
$url = $urlR; $url = $urlR;
break; break;
} }
} }
// Set new URL // Set new URL
$url = $urlR; $url = $urlR;
} }
// Return routed URL // Return routed URL
return $url; return $url;
} }
} }
?> ?>

View file

@ -1,250 +1,250 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
namespace nre\responses; namespace nre\responses;
/** /**
* Representation of a web-response. * Representation of a web-response.
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
*/ */
class WebResponse extends \nre\core\Response class WebResponse extends \nre\core\Response
{ {
/** /**
* Applied GET-parameters * Applied GET-parameters
* *
* @var array * @var array
*/ */
private $getParams = array(); private $getParams = array();
/** /**
* Changed header lines * Changed header lines
* *
* @var array * @var array
*/ */
private $headers = array(); private $headers = array();
/** /**
* Add a parameter. * Add a parameter.
* *
* @param mixed $value Value of parameter * @param mixed $value Value of parameter
*/ */
public function addParam($value) public function addParam($value)
{ {
if(array_key_exists('layout', $this->getParams)) { if(array_key_exists('layout', $this->getParams)) {
parent::addParam($value); parent::addParam($value);
} }
else { else {
$this->addGetParam('layout', $value); $this->addGetParam('layout', $value);
} }
} }
/** /**
* Add multiple parameters. * Add multiple parameters.
* *
* @param mixed $value1 Value of first parameter * @param mixed $value1 Value of first parameter
* @param mixed Values of further parameters * @param mixed Values of further parameters
*/ */
public function addParams($value1) public function addParams($value1)
{ {
$this->addParam($value1); $this->addParam($value1);
$this->params = array_merge( $this->params = array_merge(
$this->params, $this->params,
array_slice( array_slice(
func_get_args(), func_get_args(),
1 1
) )
); );
} }
/** /**
* Delete all stored parameters (from offset on). * Delete all stored parameters (from offset on).
* *
* @param int $offset Offset-index * @param int $offset Offset-index
*/ */
public function clearParams($offset=0) public function clearParams($offset=0)
{ {
if($offset == 0) { if($offset == 0) {
unset($this->getParams['layout']); unset($this->getParams['layout']);
} }
parent::clearParams(max(0, $offset-1)); parent::clearParams(max(0, $offset-1));
} }
/** /**
* Get a parameter. * Get a parameter.
* *
* @param int $index Index of parameter * @param int $index Index of parameter
* @param string $defaultIndex Index of default configuration value for this parameter * @param string $defaultIndex Index of default configuration value for this parameter
* @return string Value of parameter * @return string Value of parameter
*/ */
public function getParam($index, $defaultIndex=null) public function getParam($index, $defaultIndex=null)
{ {
if($index == 0) { if($index == 0) {
return $this->getGetParam('layout', $defaultIndex); return $this->getGetParam('layout', $defaultIndex);
} }
else { else {
return parent::getParam($index-1, $defaultIndex); return parent::getParam($index-1, $defaultIndex);
} }
} }
/** /**
* Get all parameters from index on. * Get all parameters from index on.
* *
* @param int $offset Offset-index * @param int $offset Offset-index
* @return array Parameter values * @return array Parameter values
*/ */
public function getParams($offset=0) public function getParams($offset=0)
{ {
if($offset == 0) if($offset == 0)
{ {
if(!array_key_exists('layout', $this->getParams)) { if(!array_key_exists('layout', $this->getParams)) {
return array(); return array();
} }
return array_merge( return array_merge(
array( array(
$this->getParams['layout'] $this->getParams['layout']
), ),
$this->params $this->params
); );
} }
return array_slice($this->params, $offset-1); return array_slice($this->params, $offset-1);
} }
/** /**
* Add a GET-parameter. * Add a GET-parameter.
* *
* @param string $key Key of GET-parameter * @param string $key Key of GET-parameter
* @param mixed $value Value of GET-parameter * @param mixed $value Value of GET-parameter
*/ */
public function addGetParam($key, $value) public function addGetParam($key, $value)
{ {
$this->getParams[$key] = $value; $this->getParams[$key] = $value;
} }
/** /**
* Add multiple GET-parameters. * Add multiple GET-parameters.
* *
* @param array $params Associative arary with key-value GET-parameters * @param array $params Associative arary with key-value GET-parameters
*/ */
public function addGetParams($params) public function addGetParams($params)
{ {
$this->getParams = array_merge( $this->getParams = array_merge(
$this->getParams, $this->getParams,
$params $params
); );
} }
/** /**
* Get a GET-parameter. * Get a GET-parameter.
* *
* @param int $key Index of GET-parameter * @param int $key Index of GET-parameter
* @param string $defaultIndex Index of default configuration value for this parameter * @param string $defaultIndex Index of default configuration value for this parameter
* @return string Value of GET-parameter * @return string Value of GET-parameter
*/ */
public function getGetParam($key, $defaultIndex=null) public function getGetParam($key, $defaultIndex=null)
{ {
// Check key // Check key
if(array_key_exists($key, $this->getParams)) if(array_key_exists($key, $this->getParams))
{ {
// Return value // Return value
return $this->getParams[$key]; return $this->getParams[$key];
} }
// Return default value // Return default value
return \nre\core\Config::getDefault($defaultIndex); return \nre\core\Config::getDefault($defaultIndex);
} }
/** /**
* Get all GET-parameters. * Get all GET-parameters.
* *
* @return array All GET-parameters * @return array All GET-parameters
*/ */
public function getGetParams() public function getGetParams()
{ {
return $this->getParams; return $this->getParams;
} }
/** /**
* Add a line to the response header. * Add a line to the response header.
* *
* @param string $headerLine Header line * @param string $headerLine Header line
* @param bool $replace Replace existing header line * @param bool $replace Replace existing header line
* @param int $http_response_code HTTP-response code * @param int $http_response_code HTTP-response code
*/ */
public function addHeader($headerLine, $replace=true, $http_response_code=null) public function addHeader($headerLine, $replace=true, $http_response_code=null)
{ {
$this->headers[] = $this->newHeader($headerLine, $replace, $http_response_code); $this->headers[] = $this->newHeader($headerLine, $replace, $http_response_code);
} }
/** /**
* Clear all stored headers. * Clear all stored headers.
*/ */
public function clearHeaders() public function clearHeaders()
{ {
$this->headers = array(); $this->headers = array();
} }
/** /**
* Send stored headers. * Send stored headers.
*/ */
public function header() public function header()
{ {
foreach($this->headers as $header) foreach($this->headers as $header)
{ {
header( header(
$header['string'], $header['string'],
$header['replace'], $header['replace'],
$header['responseCode'] $header['responseCode']
); );
} }
} }
/** /**
* Create a new header line. * Create a new header line.
* *
* @param string $headerLine Header line * @param string $headerLine Header line
* @param bool $replace Replace existing header line * @param bool $replace Replace existing header line
* @param int $http_response_code HTTP-response code * @param int $http_response_code HTTP-response code
*/ */
private function newHeader($headerLine, $replace=true, $http_response_code=null) private function newHeader($headerLine, $replace=true, $http_response_code=null)
{ {
return array( return array(
'string' => $headerLine, 'string' => $headerLine,
'replace' => $replace, 'replace' => $replace,
'responseCode' => $http_response_code 'responseCode' => $http_response_code
); );
} }
} }
?> ?>

View file

@ -2,12 +2,12 @@
<html> <html>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>Service Unavailable</title> <title>Service Unavailable</title>
</head> </head>
<body> <body>
<p>Die Anwendung steht zur Zeit leider nicht zur Verfügung.</p> <p>Die Anwendung steht zur Zeit leider nicht zur Verfügung.</p>
</body> </body>
</html> </html>

View file

@ -1,51 +1,51 @@
<?php <?php
/** /**
* NRE * NRE
* *
* @author coderkun <olli@coderkun.de> * @author coderkun <olli@coderkun.de>
* @copyright 2013 coderkun (http://www.coderkun.de) * @copyright 2013 coderkun (http://www.coderkun.de)
* @license http://www.gnu.org/licenses/gpl.html * @license http://www.gnu.org/licenses/gpl.html
* @link http://www.coderkun.de/projects/nre * @link http://www.coderkun.de/projects/nre
*/ */
/** /**
* Define constants * Define constants
*/ */
// Directory separator // Directory separator
if(!defined('DS')) { if(!defined('DS')) {
/** /**
* @internal * @internal
*/ */
define('DS', DIRECTORY_SEPARATOR); define('DS', DIRECTORY_SEPARATOR);
} }
// Root directory // Root directory
if(!defined('ROOT')) { if(!defined('ROOT')) {
/** /**
* @internal * @internal
*/ */
define('ROOT', dirname(dirname(__FILE__))); define('ROOT', dirname(dirname(__FILE__)));
} }
/** /**
* De-/Activate error messages * De-/Activate error messages
*/ */
if($_SERVER['SERVER_ADDR'] == '127.0.0.1' || $_SERVER['SERVER_ADDR'] == '::1') { if($_SERVER['SERVER_ADDR'] == '127.0.0.1' || $_SERVER['SERVER_ADDR'] == '::1') {
error_reporting(E_ALL); error_reporting(E_ALL);
ini_set('display_errors', 1); ini_set('display_errors', 1);
ini_set('log_errors', 0); ini_set('log_errors', 0);
} }
else { else {
error_reporting(E_ALL); error_reporting(E_ALL);
ini_set('display_errors', 0); ini_set('display_errors', 0);
ini_set('log_errors', 1); ini_set('log_errors', 1);
} }
/** /**
* Run application * Run application
*/ */
require ROOT.DS.'bootstrap.inc'; require ROOT.DS.'bootstrap.inc';
?> ?>