Merge pull request #3340 from Icinga/bugfix/php-fatal-errors-2216
Unify the look of fatal and non-fatal errors
This commit is contained in:
commit
f3404c24e5
library/Icinga/Application
|
@ -5,6 +5,7 @@ namespace Icinga\Application;
|
||||||
|
|
||||||
require_once __DIR__ . '/EmbeddedWeb.php';
|
require_once __DIR__ . '/EmbeddedWeb.php';
|
||||||
|
|
||||||
|
use ErrorException;
|
||||||
use Zend_Controller_Action_HelperBroker;
|
use Zend_Controller_Action_HelperBroker;
|
||||||
use Zend_Controller_Front;
|
use Zend_Controller_Front;
|
||||||
use Zend_Controller_Router_Route;
|
use Zend_Controller_Router_Route;
|
||||||
|
@ -96,7 +97,8 @@ class Web extends EmbeddedWeb
|
||||||
->setupUser()
|
->setupUser()
|
||||||
->setupTimezone()
|
->setupTimezone()
|
||||||
->setupLogger()
|
->setupLogger()
|
||||||
->setupInternationalization();
|
->setupInternationalization()
|
||||||
|
->setupFatalErrorHandling();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -547,6 +549,37 @@ class Web extends EmbeddedWeb
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fatal error handling configuration
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
protected function setupFatalErrorHandling()
|
||||||
|
{
|
||||||
|
register_shutdown_function(function () {
|
||||||
|
$error = error_get_last();
|
||||||
|
|
||||||
|
if ($error !== null && $error['type'] === E_ERROR) {
|
||||||
|
$frontController = Icinga::app()->getFrontController();
|
||||||
|
$response = $frontController->getResponse();
|
||||||
|
|
||||||
|
$response->setException(new ErrorException(
|
||||||
|
$error['message'],
|
||||||
|
0,
|
||||||
|
$error['type'],
|
||||||
|
$error['file'],
|
||||||
|
$error['line']
|
||||||
|
));
|
||||||
|
|
||||||
|
// Clean PHP's fatal error stack trace and replace it with ours
|
||||||
|
ob_end_clean();
|
||||||
|
$frontController->dispatch($frontController->getRequest(), $response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (non-PHPDoc)
|
||||||
* @see ApplicationBootstrap::detectTimezone() For the method documentation.
|
* @see ApplicationBootstrap::detectTimezone() For the method documentation.
|
||||||
|
|
Loading…
Reference in New Issue