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:
lippserd 2018-02-21 09:26:21 +01:00 committed by GitHub
commit f3404c24e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 1 deletions

View File

@ -5,6 +5,7 @@ namespace Icinga\Application;
require_once __DIR__ . '/EmbeddedWeb.php';
use ErrorException;
use Zend_Controller_Action_HelperBroker;
use Zend_Controller_Front;
use Zend_Controller_Router_Route;
@ -96,7 +97,8 @@ class Web extends EmbeddedWeb
->setupUser()
->setupTimezone()
->setupLogger()
->setupInternationalization();
->setupInternationalization()
->setupFatalErrorHandling();
}
/**
@ -547,6 +549,37 @@ class Web extends EmbeddedWeb
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)
* @see ApplicationBootstrap::detectTimezone() For the method documentation.