/** * 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) { $this->controller = $this->_getController($exception); if (method_exists($this->controller, 'appError')) { return $this->controller->appError($exception); } $method = $template = Inflector::variable(str_replace('Exception', '', get_class($exception))); $code = $exception->getCode(); $methodExists = method_exists($this, $method); if ($exception instanceof CakeException && !$methodExists) { $method = '_cakeError'; if (empty($template) || $template === 'internalError') { $template = 'error500'; } } elseif ($exception instanceof PDOException) { $method = 'pdoError'; $template = 'pdo_error'; $code = 500; } elseif (!$methodExists) { $method = 'error500'; if ($code >= 400 && $code < 500) { $method = 'error400'; } } $isNotDebug = !Configure::read('debug'); if ($isNotDebug && $method === '_cakeError') { $method = 'error400'; } if ($isNotDebug && $code == 500) { $method = 'error500'; } $this->template = $template; $this->method = $method; $this->error = $exception; }
/** * Class constructor. * * @param string $method Method producing the error * @param array $messages Error messages */ function __construct($method, $messages) { App::import('Core', 'Sanitize'); static $__previousError = null; if ($__previousError != array($method, $messages)) { $__previousError = array($method, $messages); $this->controller =& new CakeErrorController(); } else { $this->controller =& new Controller(); $this->controller->viewPath = 'errors'; } $options = array('escape' => false); $messages = Sanitize::clean($messages, $options); if (!isset($messages[0])) { $messages = array($messages); } if (method_exists($this->controller, 'apperror')) { return $this->controller->appError($method, $messages); } if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($this)))) { $method = 'error'; } if ($method !== 'error') { if (Configure::read() == 0) { $method = 'error404'; if (isset($code) && $code == 500) { $method = 'error500'; } } } $this->dispatchMethod($method, $messages); $this->_stop(); }
/** * 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) { $this->controller = $this->_getController($exception); if (method_exists($this->controller, 'apperror')) { return $this->controller->appError($exception); } $method = $template = Inflector::variable(str_replace('Exception', '', get_class($exception))); $code = $exception->getCode(); $methodExists = method_exists($this, $method); if ($exception instanceof CakeException && !$methodExists) { $method = '_cakeError'; if (empty($template)) { $template = 'error500'; } if ($template == 'internalError') { $template = 'error500'; } } elseif ($exception instanceof PDOException) { $method = 'pdoError'; $template = 'pdo_error'; $code = 500; } elseif (!$methodExists) { $method = 'error500'; if ($code >= 400 && $code < 500) { $method = 'error400'; } } if (Configure::read('debug') == 0) { $parentClass = get_parent_class($this); if ($parentClass != __CLASS__) { $method = 'error400'; } $parentMethods = (array)get_class_methods($parentClass); if (in_array($method, $parentMethods)) { $method = 'error400'; } if ($code == 500) { $method = 'error500'; } } $this->template = $template; $this->method = $method; $this->error = $exception; }