diff --git a/CHANGELOG.md b/CHANGELOG.md index 35cc67b..932952b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee # Version 2 +# 2.3.1 - 2026-04-25 + +- Fix compatibility issue with Symfony 8. + # 2.3.0 - 2025-01-05 - Compatibility with Symfony 8. diff --git a/src/Collector/Collector.php b/src/Collector/Collector.php index fcd6a68..747be36 100644 --- a/src/Collector/Collector.php +++ b/src/Collector/Collector.php @@ -7,6 +7,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DataCollector\DataCollector; +use Symfony\Component\HttpKernel\Kernel; /** * The Collector holds profiled Stacks pushed by the StackPlugin. It also has a list of the configured clients. @@ -19,7 +20,7 @@ * * @internal */ -final class Collector extends DataCollector +class BaseCollector extends DataCollector { private ?Stack $activeStack = null; private ?int $capturedBodyLength = null; @@ -30,13 +31,6 @@ public function __construct(?int $capturedBodyLength = null) $this->reset(); } - public function __wakeup(): void - { - $this->capturedBodyLength = null; - - parent::__wakeup(); - } - public function reset(): void { $this->data['stacks'] = []; @@ -158,4 +152,45 @@ public function collect(Request $request, Response $response, $exception = null) { // We do not need to collect any data from the Symfony Request and Response } + + protected function resetBodyLength(): void + { + $this->capturedBodyLength = null; + } +} + +if (version_compare('7.4.0', Kernel::VERSION, '>')) { + /** + * @legacy Support Symfony < 7.4 + * + * When we drop Support for Symfony < 7.4, remove this hackery. + * - Rename BaseCollector back to Collector + * - Make it final again + * - move __unserialize into BaseCollector and inline resetBodyLength + * - remove the if statement completely + * + * @internal + */ + final class Collector extends BaseCollector + { + public function __wakeup(): void + { + $this->resetBodyLength(); + + parent::__wakeup(); /* @phpstan-ignore staticMethod.notFound */ + } + } +} else { + /** + * @internal + */ + final class Collector extends BaseCollector + { + public function __unserialize(array $data): void + { + $this->resetBodyLength(); + + parent::__unserialize($data); + } + } }