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

Commit f6bc9da

Browse files
committed
Prevent deprecation notice based on triggering error middleware
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.
1 parent 5b02b23 commit f6bc9da

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

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)