Exemplo n.º 1
0
 /**
  * Runs the specified action
  *
  * @param string $action   The name of the action (without the controller specific prefix)
  *
  * @return void
  *
  * @throws \YapepBase\Exception\ControllerException   On controller specific error. (eg. action not found)
  * @throws \YapepBase\Exception\Exception             On framework related errors.
  * @throws \YapepBase\Exception\RedirectException     On redirections.
  * @throws \Exception                                 On non-framework related errors.
  */
 public function run($action)
 {
     $methodName = $this->getActionPrefix() . $action;
     if (!method_exists($this, $methodName)) {
         throw new ControllerException('Action ' . $methodName . ' does not exist in ' . get_class($this), ControllerException::ERR_ACTION_NOT_FOUND);
     }
     if (Config::getInstance()->get('system.performStrictControllerActionNameValidation', false)) {
         $reflection = new \ReflectionClass($this);
         $method = $reflection->getMethod($methodName);
         if ($method->name != $methodName) {
             throw new ControllerException('Invalid case when running action ' . $methodName . ' in ' . get_class($this) . '. The valid case is: ' . $method->name, ControllerException::ERR_ACTION_NOT_FOUND);
         }
     }
     $this->before();
     $result = $this->runAction($methodName);
     if (!empty($result) && !is_string($result) && !$result instanceof ViewAbstract) {
         throw new ControllerException('Result of the action (' . get_class($this) . '/' . $action . ') is not an instance of ViewAbstract or string', ControllerException::ERR_INVALID_ACTION_RESULT);
     }
     // We called the run method, but we did not rendered the output yet
     $this->runBeforeRender();
     $this->runBeforeResponseSet($result);
     if (!empty($result)) {
         if (is_string($result)) {
             $this->response->setRenderedBody($result);
         } else {
             $this->response->setBody($result);
         }
     }
     $this->after();
 }
Exemplo n.º 2
0
 /**
  * Sends an error to the output.
  *
  * @return void
  *
  * @codeCoverageIgnore
  */
 public function outputError()
 {
     try {
         $this->response->sendError();
     } catch (\Exception $exception) {
         error_log('Uncaught exception during error shutdown: ' . $exception->getMessage());
         exit;
     }
 }