/** * Logs the error and dispatches an error controller. * * @param \Phalcon\Error\Error $error * @return mixed */ public static function handle(Error $error) { $di = Di::getDefault(); $config = $di->getShared('config')->error; $type = static::getErrorType($error->type()); $message = "{$type}: {$error->message()} in {$error->file()} on line {$error->line()}"; if (isset($config->formatter) && $config->formatter instanceof Formatter) { $config->logger->setFormatter($config->formatter); } $config->logger->log($message); switch ($error->type()) { case E_WARNING: case E_NOTICE: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: case E_DEPRECATED: case E_USER_DEPRECATED: case E_ALL: break; case 0: case E_ERROR: case E_PARSE: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: case E_RECOVERABLE_ERROR: $dispatcher = $di->getShared('dispatcher'); $view = $di->getShared('view'); $response = $di->getShared('response'); $dispatcher->setControllerName($config->controller); $dispatcher->setActionName($config->action); $dispatcher->setParams(['error' => $error]); $view->start(); $dispatcher->dispatch(); $view->render($config->controller, $config->action, $dispatcher->getParams()); $view->finish(); return $response->setContent($view->getContent())->send(); } }
/** * Logs the error and dispatches an error controller. * * @param \Phalcon\Error\Error $error * @return mixed */ public static function handle(Error $error) { $di = Di::getDefault(); $config = $di->getShared('config')->error->toArray(); $logger = $config['logger']; if (!$logger instanceof AdapterInterface) { $logger = new FileLogger($logger); } $type = static::getErrorType($error->type()); $message = "{$type}: {$error->message()} in {$error->file()} on line {$error->line()}"; if (isset($config['formatter'])) { $formatter = null; if ($config['formatter'] instanceof Formatter) { $formatter = $config['formatter']; } elseif (is_array($config['formatter'])) { $format = null; $dateFormat = null; if (isset($config['formatter']['format'])) { $format = $config['formatter']['format']; } if (isset($config['formatter']['dateFormat'])) { $dateFormat = $config['formatter']['dateFormat']; } elseif (isset($config['formatter']['date_format'])) { $dateFormat = $config['formatter']['date_format']; } elseif (isset($config['formatter']['date'])) { $dateFormat = $config['formatter']['date']; } $formatter = new FormatterLine($format, $dateFormat); } if ($formatter) { $logger->setFormatter($formatter); } } $logger->log(static::getLogType($error->type()), $message); switch ($error->type()) { case E_WARNING: case E_NOTICE: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: case E_DEPRECATED: case E_USER_DEPRECATED: case E_ALL: break; case 0: case E_ERROR: case E_PARSE: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: case E_RECOVERABLE_ERROR: if ($di->has('view')) { $dispatcher = $di->getShared('dispatcher'); $view = $di->getShared('view'); $response = $di->getShared('response'); $dispatcher->setControllerName($config['controller']); $dispatcher->setActionName($config['action']); $dispatcher->setParams(['error' => $error]); $view->start(); $dispatcher->dispatch(); $view->render($config['controller'], $config['action'], $dispatcher->getParams()); $view->finish(); return $response->setContent($view->getContent())->send(); } else { echo $message; } } }