bug #35464 [ErrorHandler] Add debug argument to decide whether debug page is shown or not (yceruto)

This PR was merged into the 4.4 branch.

Discussion
----------

[ErrorHandler] Add debug argument to decide whether debug page is shown or not

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #35448
| License       | MIT
| Doc PR        | -

This ensures that the debug page (with stack trace) won't be (by default) displayed in non-CLI context when an early error occurs (after FB::boot()) in non-debug mode (prod). And `Debug::enable()` will enable it explicitly.

Commits
-------

cf80224589 Added debug argument to decide if debug page should be shown or not
This commit is contained in:
Nicolas Grekas 2020-01-27 10:48:47 +01:00
commit c956d62e5c
2 changed files with 5 additions and 3 deletions

View File

@ -31,6 +31,6 @@ class Debug
DebugClassLoader::enable();
return ErrorHandler::register(new ErrorHandler(new BufferingLogger()));
return ErrorHandler::register(new ErrorHandler(new BufferingLogger(), true));
}
}

View File

@ -92,6 +92,7 @@ class ErrorHandler
private $screamedErrors = 0x55; // E_ERROR + E_CORE_ERROR + E_COMPILE_ERROR + E_PARSE
private $loggedErrors = 0;
private $traceReflector;
private $debug;
private $isRecursive = 0;
private $isRoot = false;
@ -180,7 +181,7 @@ class ErrorHandler
}
}
public function __construct(BufferingLogger $bootstrappingLogger = null)
public function __construct(BufferingLogger $bootstrappingLogger = null, bool $debug = false)
{
if ($bootstrappingLogger) {
$this->bootstrappingLogger = $bootstrappingLogger;
@ -188,6 +189,7 @@ class ErrorHandler
}
$this->traceReflector = new \ReflectionProperty('Exception', 'trace');
$this->traceReflector->setAccessible(true);
$this->debug = $debug;
}
/**
@ -697,7 +699,7 @@ class ErrorHandler
*/
private function renderException(\Throwable $exception): void
{
$renderer = \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? new CliErrorRenderer() : new HtmlErrorRenderer(0 !== $this->scopedErrors);
$renderer = \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? new CliErrorRenderer() : new HtmlErrorRenderer($this->debug);
$exception = $renderer->render($exception);