winter/modules/system/classes/ErrorHandler.php

84 lines
2.5 KiB
PHP
Raw Normal View History

2014-05-14 23:24:20 +10:00
<?php namespace System\Classes;
use View;
use Config;
use Cms\Classes\Theme;
use Cms\Classes\Router;
use Cms\Classes\Controller as CmsController;
use Winter\Storm\Exception\ErrorHandler as ErrorHandlerBase;
use Winter\Storm\Exception\SystemException;
use Symfony\Component\HttpFoundation\Response;
2014-05-14 23:24:20 +10:00
/**
* System Error Handler, this class handles application exception events.
*
* @package winter\wn-system-module
2014-05-14 23:24:20 +10:00
* @author Alexey Bobkov, Samuel Georges
*/
2015-01-28 18:03:35 +11:00
class ErrorHandler extends ErrorHandlerBase
2014-05-14 23:24:20 +10:00
{
/**
2017-03-16 06:26:14 +11:00
* @inheritDoc
*/
// public function handleException(Exception $proposedException)
// {
// // The Twig runtime error is not very useful
// if (
// $proposedException instanceof \Twig\Error\RuntimeError &&
// ($previousException = $proposedException->getPrevious()) &&
// (!$previousException instanceof CmsException)
// ) {
// $proposedException = $previousException;
// }
// return parent::handleException($proposedException);
// }
2014-05-14 23:24:20 +10:00
/**
* Looks up an error page using the CMS route "/error". If the route does not
* exist, this function will use the error view found in the Cms module.
* @return mixed Error page contents.
*/
public function handleCustomError()
{
if (Config::get('app.debug', false)) {
2015-01-28 18:03:35 +11:00
return null;
}
2015-01-28 18:03:35 +11:00
if (class_exists(Theme::class) && in_array('Cms', Config::get('cms.loadModules', []))) {
$theme = Theme::getActiveTheme();
$router = new Router($theme);
2014-05-14 23:24:20 +10:00
// Use the default view if no "/error" URL is found.
if (!$router->findByUrl('/error')) {
return View::make('cms::error');
}
2014-05-14 23:24:20 +10:00
// Route to the CMS error page.
$controller = new CmsController($theme);
$result = $controller->run('/error');
} else {
$result = View::make('system::error');
}
// Extract content from response object
if ($result instanceof Response) {
$result = $result->getContent();
}
return $result;
2014-05-14 23:24:20 +10:00
}
2015-01-28 18:03:35 +11:00
/**
* Displays the detailed system exception page.
* @return View Object containing the error page.
*/
public function handleDetailedError($exception)
{
// Ensure System view path is registered
View::addNamespace('system', base_path().'/modules/system/views');
return View::make('system::exception', ['exception' => $exception]);
}
2014-10-18 11:58:50 +02:00
}