Ejemplo n.º 1
0
 /**
  * Creates the controller to perform rendering on the error response.
  * If the error is a CakeException it will be converted to either a 400 or a 500
  * code error depending on the code used to construct the error.
  *
  * @param Exception $exception Exception
  */
 public function __construct(Exception $exception, Application $app)
 {
     $this->_app = $app;
     $this->controller = new Controller($app['request'], $app['response']);
     if (method_exists($this->controller, 'appError')) {
         $this->controller->appError($exception);
         return;
     }
     $exceptionName = explode('\\', str_replace('Exception', '', get_class($exception)));
     $exceptionName = array_pop($exceptionName);
     $method = $template = Inflector::variable($exceptionName);
     $code = $exception->getCode();
     $methodExists = method_exists($this, $method);
     if ($exception instanceof PrimerException && !$methodExists) {
         $method = '_primerError';
         if (empty($template) || $template === 'internalError') {
             $template = 'error500';
         }
     } else {
         if ($exception instanceof PDOException) {
             $method = 'pdoError';
             $template = 'pdo_error';
             $code = 500;
         } else {
             if (!$methodExists) {
                 $method = 'error500';
                 if ($code >= 400 && $code < 500) {
                     $method = 'error400';
                 }
             }
         }
     }
     $isNotDebug = !$this->_app['config']['app.debug'];
     if ($isNotDebug && $method === '_primerError') {
         $method = 'error400';
     }
     if ($isNotDebug && $code == 500) {
         $method = 'error500';
     }
     $this->template = $template;
     $this->method = $method;
     $this->error = $exception;
 }