Explorar o código

Merge branch '2.x'

Jordi Boggiano %!s(int64=2) %!d(string=hai) anos
pai
achega
70f6ca05b9

+ 1 - 1
src/Monolog/Formatter/LineFormatter.php

@@ -162,7 +162,7 @@ class LineFormatter extends NormalizerFormatter
             do {
                 $depth++;
                 if ($depth > $this->maxNormalizeDepth) {
-                    $str .= '\n[previous exception] Over ' . $this->maxNormalizeDepth . ' levels deep, aborting normalization';
+                    $str .= "\n[previous exception] Over " . $this->maxNormalizeDepth . ' levels deep, aborting normalization';
                     break;
                 }
 

+ 3 - 0
src/Monolog/Formatter/NormalizerFormatter.php

@@ -206,6 +206,9 @@ class NormalizerFormatter implements FormatterInterface
             if ($data instanceof \JsonSerializable) {
                 /** @var null|scalar|array<mixed[]|scalar|null> $value */
                 $value = $data->jsonSerialize();
+            } elseif (\get_class($data) === '__PHP_Incomplete_Class') {
+                $accessor = new \ArrayObject($data);
+                $value = (string) $accessor['__PHP_Incomplete_Class_Name'];
             } elseif (method_exists($data, '__toString')) {
                 /** @var string $value */
                 $value = $data->__toString();

+ 7 - 4
src/Monolog/Handler/StreamHandler.php

@@ -123,11 +123,14 @@ class StreamHandler extends AbstractProcessingHandler
             $this->createDir($url);
             $this->errorMessage = null;
             set_error_handler([$this, 'customErrorHandler']);
-            $stream = fopen($url, 'a');
-            if ($this->filePermission !== null) {
-                @chmod($url, $this->filePermission);
+            try {
+                $stream = fopen($url, 'a');
+                if ($this->filePermission !== null) {
+                    @chmod($url, $this->filePermission);
+                }
+            } finally {
+                restore_error_handler();
             }
-            restore_error_handler();
             if (!is_resource($stream)) {
                 $this->stream = null;
 

+ 14 - 0
tests/Monolog/Formatter/NormalizerFormatterTest.php

@@ -402,6 +402,20 @@ class NormalizerFormatterTest extends TestCase
         );
     }
 
+    public function testCanNormalizeIncompleteObject(): void
+    {
+        $serialized = "O:17:\"Monolog\TestClass\":1:{s:23:\"\x00Monolog\TestClass\x00name\";s:4:\"test\";}";
+        $object = unserialize($serialized);
+
+        $formatter = new NormalizerFormatter();
+        $record = $this->getRecord(context: ['object' => $object]);
+        $result = $formatter->format($record);
+
+        $this->assertEquals([
+            '__PHP_Incomplete_Class' => 'Monolog\\TestClass',
+        ], $result['context']['object']);
+    }
+
     private function throwHelper($arg)
     {
         throw new \RuntimeException('Thrown');