1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-30 09:50:26 +02:00

Fix error handler to not receive $context anymore as php8 dropped that

This commit is contained in:
Jordi Boggiano
2022-04-22 21:32:10 +02:00
parent a7de8dd0c2
commit 1c80bce4ad
2 changed files with 8 additions and 11 deletions

View File

@@ -110,7 +110,7 @@ class ErrorHandler
*/
public function registerErrorHandler(array $levelMap = [], bool $callPrevious = true, int $errorTypes = -1, bool $handleOnlyReportedErrors = true): self
{
$prev = set_error_handler([$this, 'handleError'], $errorTypes);
$prev = set_error_handler($this->handleError(...), $errorTypes);
$this->errorLevelMap = array_replace($this->defaultErrorLevelMap(), $levelMap);
if ($callPrevious) {
$this->previousErrorHandler = $prev !== null ? $prev(...) : true;
@@ -129,7 +129,7 @@ class ErrorHandler
*/
public function registerFatalHandler($level = null, int $reservedMemorySize = 20): self
{
register_shutdown_function([$this, 'handleFatalError']);
register_shutdown_function($this->handleFatalError(...));
$this->reservedMemory = str_repeat(' ', 1024 * $reservedMemorySize);
$this->fatalLevel = null === $level ? LogLevel::ALERT : $level;
@@ -200,12 +200,7 @@ class ErrorHandler
exit(255);
}
/**
* @private
*
* @param mixed[] $context
*/
public function handleError(int $code, string $message, string $file = '', int $line = 0, ?array $context = []): bool
private function handleError(int $code, string $message, string $file = '', int $line = 0): bool
{
if ($this->handleOnlyReportedErrors && !(error_reporting() & $code)) {
return false;
@@ -223,8 +218,9 @@ class ErrorHandler
if ($this->previousErrorHandler === true) {
return false;
} elseif ($this->previousErrorHandler) {
return (bool) ($this->previousErrorHandler)($code, $message, $file, $line, $context);
}
if ($this->previousErrorHandler) {
return (bool) ($this->previousErrorHandler)($code, $message, $file, $line);
}
return true;

View File

@@ -176,7 +176,8 @@ class PHPConsoleHandlerTest extends TestCase
);
$errorHandler = ErrorHandler::register($this->initLogger($classesPartialsTraceIgnore ? ['classesPartialsTraceIgnore' => $classesPartialsTraceIgnore] : []), false);
$errorHandler->registerErrorHandler([], false, E_USER_WARNING);
$errorHandler->handleError($code, $message, $file, $line);
$reflMethod = new \ReflectionMethod($errorHandler, 'handleError');
$reflMethod->invoke($errorHandler, $code, $message, $file, $line);
}
public function testException()