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

Commit 060e02f

Browse files
committed
Merge branch 'hotfix/error-middleware-deprecation-handling'
Close #395
2 parents 5b02b23 + fc250dc commit 060e02f

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22

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

5+
## 1.0.3 - 2016-11-11
6+
7+
### Added
8+
9+
- Nothing.
10+
11+
### Changes
12+
13+
- [#395](https://github.com/zendframework/zend-expressive/pull/395) updates
14+
`Application::__invoke()` to add an error handler to swallow deprecation
15+
notices due to triggering error middleware when using Stratigility 1.3+. Since
16+
error middleware is triggered whenever the `raiseThrowables` flag is not
17+
enabled and an error or empty queue situation is encountered, handling it this
18+
way prevents any such errors from bubbling out of the application.
19+
20+
### Deprecated
21+
22+
- Nothing.
23+
24+
### Removed
25+
26+
- Nothing.
27+
28+
### Fixed
29+
30+
- Nothing.
31+
532
## 1.0.2 - 2016-11-11
633

734
### Added

src/Application.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,31 @@ public function __construct(
130130
* If $out is not provided, uses the result of `getFinalHandler()`.
131131
*
132132
* @todo Remove logic for creating final handler for version 2.0.
133+
* @todo Remove error handler for deprecation notice due to triggering
134+
* error middleware for version 2.0.0.
133135
* @param ServerRequestInterface $request
134136
* @param ResponseInterface $response
135137
* @param callable|null $out
136138
* @return ResponseInterface
137139
*/
138140
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null)
139141
{
142+
set_error_handler(function ($errno, $errstr) {
143+
return false !== strstr($errstr, 'error middleware is deprecated');
144+
}, E_USER_DEPRECATED);
145+
140146
if (! $out && (null === ($out = $this->getFinalHandler($response)))) {
141147
$response = $response instanceof StratigilityResponse
142148
? $response
143149
: new StratigilityResponse($response);
144150
$out = new FinalHandler([], $response);
145151
}
146152

147-
return parent::__invoke($request, $response, $out);
153+
$result = parent::__invoke($request, $response, $out);
154+
155+
restore_error_handler();
156+
157+
return $result;
148158
}
149159

150160
/**

test/Container/ApplicationFactoryIntegrationTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,8 @@ public function testConfiguredErrorMiddlewarePipeIsExecutedWhenMiddlewareCallsNe
128128
$request = new ServerRequest([], [], 'http://example.com/needs/authentication', 'GET');
129129
$response = new Response();
130130

131-
set_error_handler(function ($errno, $errstr) {
132-
return false !== strstr($errstr, 'error middleware is deprecated');
133-
}, E_USER_DEPRECATED);
134-
135131
$response = $app($request, $response);
136132

137-
restore_error_handler();
138-
139133
$this->assertInstanceOf(ResponseInterface::class, $response);
140134
$this->assertEquals(401, $response->getStatusCode(), 'Unexpected response');
141135
$this->assertTrue($response->hasHeader('X-Always'));
@@ -222,14 +216,8 @@ public function testConfiguredErrorMiddlewareIsExecutedWhenMiddlewareCallsNextWi
222216
$request = new ServerRequest([], [], 'http://example.com/needs/authentication', 'GET');
223217
$response = new Response();
224218

225-
set_error_handler(function ($errno, $errstr) {
226-
return false !== strstr($errstr, 'error middleware is deprecated');
227-
}, E_USER_DEPRECATED);
228-
229219
$response = $app($request, $response);
230220

231-
restore_error_handler();
232-
233221
$this->assertInstanceOf(ResponseInterface::class, $response);
234222
$this->assertEquals(401, $response->getStatusCode(), 'Unexpected response');
235223
$this->assertTrue($response->hasHeader('X-Always'));

0 commit comments

Comments
 (0)