This commit is contained in:
2020-09-10 11:42:35 +08:00
parent 1d7b39cdf8
commit 6060c6937e
2 changed files with 45 additions and 18 deletions
+23 -15
View File
@@ -36,21 +36,8 @@ class OnRequest extends Callback
public function onHandler(Request $request, Response $response)
{
try {
register_shutdown_function(function ($response) {
$error = error_get_last();
if (!isset($error['type'])) {
return;
}
$types = [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR];
if (!in_array($error['type'], $types)) {
return;
}
if ($response instanceof Response) {
$response->status(500);
$response->end($error['message']);
}
unset($response);
}, $response);
register_shutdown_function([static::class, 'shutdown'], $response);
/** @var HRequest $sRequest */
[$sRequest, $sResponse] = static::setContext($request, $response);
if ($sRequest->is('favicon.ico')) {
@@ -69,6 +56,27 @@ class OnRequest extends Callback
}
/**
* @param $response
*/
public static function shutdown($response)
{
$error = error_get_last();
if (!isset($error['type'])) {
return;
}
$types = [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR];
if (!in_array($error['type'], $types)) {
return;
}
if ($response instanceof Response) {
$response->status(500);
$response->end($error['message']);
}
unset($response);
}
/**
* @param $sResponse
* @param $exception