1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69:
<?php
namespace Core\Exceptions;
use Core\ParentController;
/**
* Class Exception contains the page shown on Exceptions (<b>throw new Exception($e)</b>).
* It is called by default on such cases.
*
* @hooks
* <code>
* ('show_prod_exception', ['e' => $e]) // Called when an exception is thrown on the PROD environment {@see \Core\Exception::showException}
* ('show_dev_exception', ['e' => $e]) // Called when an exception is thrown on the DEV environment {@see \Core\Exception::showException}
* </code>
* @package Core
*/
class Exception extends ParentController {
/**
* @var Exception The class instance.
* @internal
*/
protected static $instance;
/**
* Returns the Exception instance, creating it if it did not exist.
* @return Exception
*/
public static function singleton($path = FALSE) {
if (!self::$instance) {
$c = __CLASS__;
self::$instance = new $c($path);
}
return self::$instance;
}
/**
* Outputs a 500 header. In <b>dev</b> mode and in localhost shows the catched exception with debug information, otherwise a 500 page is shown.
* @see isLocalServer()
* @see isProd()
* @see isDev()
* @param \Exception $e
*/
public function showException(\Exception $e) {
if (isProd() && !isLocalServer()) {
$this->hooks->do_action('show_prod_exception', ['e' => $e]);
$this
->header(500)
->setTitle('500 Internal Server Error')
->add('e', $e)
->show('exception/exception');
} else /* isDev() */ {
$this->hooks->do_action('show_dev_exception', ['e' => $e]);
$trace = $e->getTrace();
$this
->header(500)
->setTitle('Rendering Exception')
->add('e', $e)
->add('routing', $this->config->get("Routing"))
->add('trace', $trace)
->addStyle('libs/bootstrap/themes/paper_theme.css')
->show('exception/renderingException');
}
}
}