Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Prevent deprecation notice based on triggering error middleware
Browse files Browse the repository at this point in the history
Users cannot yet set the raiseThrowables flag, as there are not shipped
facilities for handling errors using templates or whoops. As such,
currently, if the queue is exhausted or an exception is thrown, error
middleware is triggered. This patch adds an error handler to
`Application::__invoke()` to swallow deprecation notices due to
invocation of error middleware.
  • Loading branch information
weierophinney committed Nov 11, 2016
1 parent 5b02b23 commit f6bc9da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
12 changes: 11 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,31 @@ public function __construct(
* If $out is not provided, uses the result of `getFinalHandler()`.
*
* @todo Remove logic for creating final handler for version 2.0.
* @todo Remove error handler for deprecation notice due to triggering
* error middleware for version 2.0.0.
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable|null $out
* @return ResponseInterface
*/
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);

if (! $out && (null === ($out = $this->getFinalHandler($response)))) {
$response = $response instanceof StratigilityResponse
? $response
: new StratigilityResponse($response);
$out = new FinalHandler([], $response);
}

return parent::__invoke($request, $response, $out);
$result = parent::__invoke($request, $response, $out);

restore_error_handler();

return $result;
}

/**
Expand Down
12 changes: 0 additions & 12 deletions test/Container/ApplicationFactoryIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,8 @@ public function testConfiguredErrorMiddlewarePipeIsExecutedWhenMiddlewareCallsNe
$request = new ServerRequest([], [], 'http://example.com/needs/authentication', 'GET');
$response = new Response();

set_error_handler(function ($errno, $errstr) {
return false !== strstr($errstr, 'error middleware is deprecated');
}, E_USER_DEPRECATED);

$response = $app($request, $response);

restore_error_handler();

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals(401, $response->getStatusCode(), 'Unexpected response');
$this->assertTrue($response->hasHeader('X-Always'));
Expand Down Expand Up @@ -222,14 +216,8 @@ public function testConfiguredErrorMiddlewareIsExecutedWhenMiddlewareCallsNextWi
$request = new ServerRequest([], [], 'http://example.com/needs/authentication', 'GET');
$response = new Response();

set_error_handler(function ($errno, $errstr) {
return false !== strstr($errstr, 'error middleware is deprecated');
}, E_USER_DEPRECATED);

$response = $app($request, $response);

restore_error_handler();

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals(401, $response->getStatusCode(), 'Unexpected response');
$this->assertTrue($response->hasHeader('X-Always'));
Expand Down

0 comments on commit f6bc9da

Please sign in to comment.