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

Commit ba33c2a

Browse files
committed
Merge branch 'hotfix/404'
Close #404
2 parents d6be3ee + 6351422 commit ba33c2a

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ All notable changes to this project will be documented in this file, in reverse
3333
it now creates a new `Zend\Diactoros\Stream`, writes to that, and returns a
3434
new response with that new stream, guaranteeing it only contains the new
3535
contents.
36+
- [#404](https://github.com/zendframework/zend-expressive/pull/404) fixes the
37+
`swallowDeprecationNotices()` handler such that it will not swallow a global
38+
handler once application execution completes.
3639

3740
## 1.0.4 - 2016-12-07
3841

src/Application.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -677,24 +677,17 @@ private function checkForDuplicateRoute($path, $methods = null)
677677
*/
678678
private function swallowDeprecationNotices()
679679
{
680-
$handler = function ($errno, $errstr) {
681-
if ($errno !== E_USER_DEPRECATED) {
682-
return false;
680+
$previous = null;
681+
$handler = function ($errno, $errstr, $errfile, $errline, $errcontext) use (&$previous) {
682+
$swallow = $errno === E_USER_DEPRECATED && false !== strstr($errstr, 'error middleware is deprecated');
683+
684+
if ($swallow || $previous === null) {
685+
return $swallow;
683686
}
684-
return false !== strstr($errstr, 'error middleware is deprecated');
687+
688+
$previous($errno, $errstr, $errfile, $errline, $errcontext);
685689
};
686690

687691
$previous = set_error_handler($handler);
688-
if (! $previous) {
689-
return;
690-
}
691-
692-
set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) use ($handler, $previous) {
693-
if ($handler($errno, $errstr)) {
694-
return true;
695-
}
696-
697-
return $previous($errno, $errstr, $errfile, $errline, $errcontext);
698-
});
699692
}
700693
}

test/IntegrationTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public function testInjectedFinalHandlerCanEmitA404WhenNoMiddlewareMatches()
8484
*/
8585
public function testErrorMiddlewareDeprecationErrorHandlerWillNotOverridePreviouslyRegisteredErrorHandler()
8686
{
87-
$triggered = false;
87+
$triggered = 0;
8888
$this->errorHandler = set_error_handler(function ($errno, $errstr) use (&$triggered) {
89-
$triggered = true;
89+
$triggered++;
9090
return true;
9191
});
9292

@@ -104,6 +104,10 @@ public function testErrorMiddlewareDeprecationErrorHandlerWillNotOverridePreviou
104104

105105
$app->run($request, $response);
106106

107-
$this->assertTrue($triggered);
107+
trigger_error('Triggered', E_USER_NOTICE);
108+
109+
restore_error_handler();
110+
111+
$this->assertSame(2, $triggered);
108112
}
109113
}

0 commit comments

Comments
 (0)