Explorar o código

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

Jordi Boggiano %!s(int64=3) %!d(string=hai) anos
pai
achega
1c80bce4ad

+ 6 - 10
src/Monolog/ErrorHandler.php

@@ -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;

+ 2 - 1
tests/Monolog/Handler/PHPConsoleHandlerTest.php

@@ -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()