/** * Run specified action * * @param string $action action name * @throws NotFoundException */ public function execute($action) { $action_name = str_replace('-', '', $action); $action_name = str_replace('_', '', $action_name); $action_name .= 'Action'; if (!method_exists($this, $action_name)) { throw new NotFoundException("Could not find '{$action}'"); } // initial tasks $init = $this->init(); if ($init instanceof HttpFoundation\Response) { return $init; } // check authentication $auth = $this->checkAuthentication($action); if ($auth instanceof HttpFoundation\Response) { return $auth; } // run the action $response = $this->{$action_name}(); // make sure we got a response if (!$response instanceof HttpFoundation\Response) { // nope, but see if we still have the original $response = $this->response; if (!$response instanceof HttpFoundation\Response) { throw new \Exception("Action '{$action}' returned no Response"); } } // this was a redirect or something if (!$response instanceof Response) { return $response; } // add event objects to response if ($this->response->getVariable('base_url') == '') { $this->response->setVariable('base_url', $this->request->getServerUrl() . $this->request->getBasePath()); $this->response->setVariable('request', $this->request); $this->response->setVariable('config', $this->registry); } // clean-up tasks $shutdown = $this->shutdown(); if ($shutdown instanceof HttpFoundation\Response) { return $shutdown; } return $response; }