/** * Execute controller method * * @throws \Arbor\Exception\ActionNotFoundException * @since 0.1.0 */ protected function callMethod() { $this->resources->registerPresenter($this->getPresenter()); $response = new Response(); $response->setPresenter($this->resources->getPresenter()); $event = new ExecuteActionEvent($this->request); $this->eventManager->fire('executeAction', $event); if (!$event->getResponse()) { $controllerName = $this->request->getClass(); $controller = new $controllerName($this->request, $this->resources); if (!is_callable(array($controller, $this->request->getMethod()))) { throw new ActionNotFoundException($controllerName, $this->request->getMethod()); } $controllerData = call_user_func_array(array($controller, $this->request->getMethod()), $this->request->getArguments()); if ($controllerData instanceof Response) { $response = $controllerData; if (!$response->getPresenter()) { $response->setPresenter($this->resources->getPresenter()); } else { $this->resources->registerPresenter($response->getPresenter()); } } else { $response->setContent($controllerData); } $event = new ExecutedActionEvent($this->request, $response); $this->eventManager->fire('executedAction', $event); } else { $response = $event->getResponse(); } $this->resources->registerResponse($response); $this->prepareView($this->request, $this->resources->getPresenter(), $response); }
/** * Find presenter for error action. * * @return \Arbor\Core\Presenter * @since 0.1.0 */ private function findPresenter() { $url = $this->resources->getUrl(); if ($this->resources->getGlobalConfig()) { foreach ($this->resources->getGlobalConfig()->getErrors() as $pattern => $presenterName) { if (preg_match('/^' . $pattern . '$/', $url)) { return new $presenterName(); } } } return new HTML(); }
private function registerSnippets(ExecuteResources $executeResources) { foreach ($executeResources->getGlobalConfig()->getSnippets() as $snippet => $class) { $executeResources->registerSnippet($snippet, new $class()); } }