1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-09 06:36:46 +02:00

Fix serialization to include private properties, fixes #1727, fixes phpro/grumphp#1020

This commit is contained in:
Jordi Boggiano
2022-07-22 20:49:07 +02:00
parent ffd505543c
commit 4b4fad9476
2 changed files with 21 additions and 1 deletions

View File

@@ -48,6 +48,15 @@ abstract class Handler implements HandlerInterface
{
$this->close();
return array_keys(get_object_vars($this));
$reflClass = new \ReflectionClass($this);
$keys = [];
foreach ($reflClass->getProperties() as $reflProp) {
if (!$reflProp->isStatic()) {
$keys[] = $reflProp->getName();
}
}
return $keys;
}
}

View File

@@ -30,4 +30,15 @@ class NullHandlerTest extends TestCase
$handler = new NullHandler(Logger::WARNING);
$this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG)));
}
public function testSerializeRestorePrivate()
{
$handler = new NullHandler(Logger::WARNING);
self::assertFalse($handler->handle($this->getRecord(Logger::DEBUG)));
self::assertTrue($handler->handle($this->getRecord(Logger::WARNING)));
$handler = unserialize(serialize($handler));
self::assertFalse($handler->handle($this->getRecord(Logger::DEBUG)));
self::assertTrue($handler->handle($this->getRecord(Logger::WARNING)));
}
}