/** * Authentication constructor. */ public function __construct() { parent::__construct(); $this->addBeforeFilters(array('loadAssets')); $this->addAfterFilters(array('loadFlashMessage')); if (Core\Config()->CAPTCHA['enabled'] && in_array(Core\Router()->request->action(), array('login', 'reset'))) { $this->loadCaptcha(Core\Config()->CAPTCHA); } }
/** * Resource constructor. */ public function __construct() { parent::__construct(); if ($this->resourceModel) { $this->addBeforeFilters(array('loadDefaultResource')); $this->addBeforeFilters(array('loadAttributeSections'), array('except' => 'delete')); $this->addBeforeFilters(array('loadResource'), array('only' => array('show', 'edit', 'delete'))); $this->addAfterFilters(array('loadFlashMessage')); } }
/** * Dispatches the processed request. * * @param Request $request Router Request object. * @param Routes $routes Router Routes object. * * @access public * @throws \InvalidArgumentException Request token does not match. * * @return void */ public function dispatch(Request &$request, Routes &$routes) { $this->routes = $routes; $this->request = $request; $this->response = new Response(); if (Core\Session()->get('_token')) { $this->request->setToken(Core\Session()->get('_token')); } else { $this->request->regenerateToken(); Core\Session()->set('_token', $this->request->token()); } if (!$request->isValid()) { $this->response->setHttpResponseCode(403); throw new \InvalidArgumentException('Request token does not match.'); } $namespace = $request->mode('namespace'); $controller = "\\{$namespace}\\Controllers\\" . $request->controller(); if (class_exists($controller)) { $controller = new $controller(); $action = $request->action(); /* Check if there is such action implemented and filter for magic methods like __construct, etc. */ if (is_callable(array($controller, $action)) && false === strpos($action, '__')) { $controller->__executeAction($action, $request); } else { $controller->__executeAction('actionNotFound', $request); } $this->response->setContent($controller->renderer->getOutput()); $this->response->addHeader('Content-Type: ' . $controller->renderer->getOutputContentType()); } else { Core\Base\Controller::resourceNotFound($request); } }