Skip to content

Commit ea0183f

Browse files
authored
Merge pull request #487 from php-http/fix-symfony-8-compat
fix: DataCollector __wakeup changed to __unserialize in Symfony 8
2 parents ef11ccf + b910470 commit ea0183f

2 files changed

Lines changed: 47 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
44

55
# Version 2
66

7+
# 2.3.1 - 2026-04-25
8+
9+
- Fix compatibility issue with Symfony 8.
10+
711
# 2.3.0 - 2025-01-05
812

913
- Compatibility with Symfony 8.

src/Collector/Collector.php

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\HttpFoundation\Request;
88
use Symfony\Component\HttpFoundation\Response;
99
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
10+
use Symfony\Component\HttpKernel\Kernel;
1011

1112
/**
1213
* The Collector holds profiled Stacks pushed by the StackPlugin. It also has a list of the configured clients.
@@ -19,7 +20,7 @@
1920
*
2021
* @internal
2122
*/
22-
final class Collector extends DataCollector
23+
class BaseCollector extends DataCollector
2324
{
2425
private ?Stack $activeStack = null;
2526
private ?int $capturedBodyLength = null;
@@ -30,13 +31,6 @@ public function __construct(?int $capturedBodyLength = null)
3031
$this->reset();
3132
}
3233

33-
public function __wakeup(): void
34-
{
35-
$this->capturedBodyLength = null;
36-
37-
parent::__wakeup();
38-
}
39-
4034
public function reset(): void
4135
{
4236
$this->data['stacks'] = [];
@@ -158,4 +152,45 @@ public function collect(Request $request, Response $response, $exception = null)
158152
{
159153
// We do not need to collect any data from the Symfony Request and Response
160154
}
155+
156+
protected function resetBodyLength(): void
157+
{
158+
$this->capturedBodyLength = null;
159+
}
160+
}
161+
162+
if (version_compare('7.4.0', Kernel::VERSION, '>')) {
163+
/**
164+
* @legacy Support Symfony < 7.4
165+
*
166+
* When we drop Support for Symfony < 7.4, remove this hackery.
167+
* - Rename BaseCollector back to Collector
168+
* - Make it final again
169+
* - move __unserialize into BaseCollector and inline resetBodyLength
170+
* - remove the if statement completely
171+
*
172+
* @internal
173+
*/
174+
final class Collector extends BaseCollector
175+
{
176+
public function __wakeup(): void
177+
{
178+
$this->resetBodyLength();
179+
180+
parent::__wakeup(); /* @phpstan-ignore staticMethod.notFound */
181+
}
182+
}
183+
} else {
184+
/**
185+
* @internal
186+
*/
187+
final class Collector extends BaseCollector
188+
{
189+
public function __unserialize(array $data): void
190+
{
191+
$this->resetBodyLength();
192+
193+
parent::__unserialize($data);
194+
}
195+
}
161196
}

0 commit comments

Comments
 (0)