Merge pull request #632 from staabm/patch-3

Make sure we close all output-buffer we started beforehand
This commit is contained in:
Denis Sokolov
2019-07-04 16:34:53 +03:00
committed by GitHub
2 changed files with 33 additions and 28 deletions
+24 -22
View File
@@ -303,38 +303,40 @@ final class Run implements RunInterface
// we might want to send it straight away to the client,
// or return it silently.
$this->system->startOutputBuffering();
// Just in case there are no handlers:
$handlerResponse = null;
$handlerContentType = null;
foreach ($this->handlerQueue as $handler) {
$handler->setRun($this);
$handler->setInspector($inspector);
$handler->setException($exception);
try {
foreach ($this->handlerQueue as $handler) {
$handler->setRun($this);
$handler->setInspector($inspector);
$handler->setException($exception);
// The HandlerInterface does not require an Exception passed to handle()
// and neither of our bundled handlers use it.
// However, 3rd party handlers may have already relied on this parameter,
// and removing it would be possibly breaking for users.
$handlerResponse = $handler->handle($exception);
// The HandlerInterface does not require an Exception passed to handle()
// and neither of our bundled handlers use it.
// However, 3rd party handlers may have already relied on this parameter,
// and removing it would be possibly breaking for users.
$handlerResponse = $handler->handle($exception);
// Collect the content type for possible sending in the headers.
$handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null;
// Collect the content type for possible sending in the headers.
$handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null;
if (in_array($handlerResponse, [Handler::LAST_HANDLER, Handler::QUIT])) {
// The Handler has handled the exception in some way, and
// wishes to quit execution (Handler::QUIT), or skip any
// other handlers (Handler::LAST_HANDLER). If $this->allowQuit
// is false, Handler::QUIT behaves like Handler::LAST_HANDLER
break;
if (in_array($handlerResponse, [Handler::LAST_HANDLER, Handler::QUIT])) {
// The Handler has handled the exception in some way, and
// wishes to quit execution (Handler::QUIT), or skip any
// other handlers (Handler::LAST_HANDLER). If $this->allowQuit
// is false, Handler::QUIT behaves like Handler::LAST_HANDLER
break;
}
}
$willQuit = $handlerResponse == Handler::QUIT && $this->allowQuit();
} finally {
$output = $this->system->cleanOutputBuffer();
}
$willQuit = $handlerResponse == Handler::QUIT && $this->allowQuit();
$output = $this->system->cleanOutputBuffer();
// If we're allowed to, send output generated by handlers directly
// to the output, otherwise, and if the script doesn't quit, return
// it so that it may be used by the caller
@@ -63,10 +63,13 @@ class PlainTextHandlerTest extends TestCase
$run->register();
$exception = $exception ?: $this->getException();
ob_start();
$run->handleException($exception);
return ob_get_clean();
try {
ob_start();
$run->handleException($exception);
} finally {
return ob_get_clean();
}
}
/**
@@ -266,11 +269,11 @@ class PlainTextHandlerTest extends TestCase
RuntimeException::class,
'Outer exception message',
__FILE__,
258,
261,
"\nCaused by\n" . RuntimeException::class,
'Inner exception message',
__FILE__,
258
261
),
$text
);