Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ public function __construct(
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null)
{
set_error_handler(function ($errno, $errstr) {
return false !== strstr($errstr, 'error middleware is deprecated');
}, E_USER_DEPRECATED);
$this->registerDeprecatedHandler();

if (! $out && (null === ($out = $this->getFinalHandler($response)))) {
$response = $response instanceof StratigilityResponse
Expand Down Expand Up @@ -671,4 +669,28 @@ private function checkForDuplicateRoute($path, $methods = null)
);
}
}

/**
* Register error handler, see issue #400
*/
private function registerDeprecatedHandler()
{
$holder = new \stdClass;
$holder->handler = null;

$handler = function ($no, $str, $file, $line) use ($holder) {
$ignore = true;
$ignore = $ignore && $no === E_USER_DEPRECATED;
$ignore = $ignore && strpos($str, 'error middleware is deprecated') !== false;
$fn = $holder->handler;

if ($ignore || $fn === null) {
return $fn !== null;
}

return $fn($no, $str, $file, $line);
};

$holder->handler = set_error_handler($handler);
}
}