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

Commit

Permalink
Merge branch 'hotfix/error-middleware-deprecation-handling'
Browse files Browse the repository at this point in the history
Close #395
  • Loading branch information
weierophinney committed Nov 11, 2016
2 parents 5b02b23 + fc250dc commit 060e02f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 1.0.3 - 2016-11-11

### Added

- Nothing.

### Changes

- [#395](https://github.com/zendframework/zend-expressive/pull/395) updates
`Application::__invoke()` to add an error handler to swallow deprecation
notices due to triggering error middleware when using Stratigility 1.3+. Since
error middleware is triggered whenever the `raiseThrowables` flag is not
enabled and an error or empty queue situation is encountered, handling it this
way prevents any such errors from bubbling out of the application.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

## 1.0.2 - 2016-11-11

### Added
Expand Down
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 060e02f

Please sign in to comment.