Skip to content

Commit 299523b

Browse files
Replace __sleep/wakeup() by __(un)serialize() for throwing and internal usages
1 parent 20c93d7 commit 299523b

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

DataCollector/DumpDataCollector.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ public function reset(): void
143143
$this->clonesIndex = 0;
144144
}
145145

146-
/**
147-
* @internal
148-
*/
149-
public function __sleep(): array
146+
public function __serialize(): array
150147
{
151148
if (!$this->dataCount) {
152149
$this->data = [];
@@ -161,16 +158,12 @@ public function __sleep(): array
161158
$this->dataCount = 0;
162159
$this->isCollected = true;
163160

164-
return parent::__sleep();
161+
return ['data' => $this->data];
165162
}
166163

167-
/**
168-
* @internal
169-
*/
170-
public function __wakeup(): void
164+
public function __unserialize(array $data): void
171165
{
172-
parent::__wakeup();
173-
166+
$this->data = array_pop($data) ?? [];
174167
$charset = array_pop($this->data);
175168
$fileLinkFormat = array_pop($this->data);
176169
$this->dataCount = \count($this->data);
@@ -180,7 +173,7 @@ public function __wakeup(): void
180173
}
181174
}
182175

183-
self::__construct($this->stopwatch, \is_string($fileLinkFormat) || $fileLinkFormat instanceof FileLinkFormatter ? $fileLinkFormat : null, \is_string($charset) ? $charset : null);
176+
self::__construct($this->stopwatch ?? null, \is_string($fileLinkFormat) || $fileLinkFormat instanceof FileLinkFormatter ? $fileLinkFormat : null, \is_string($charset) ? $charset : null);
184177
}
185178

186179
public function getDumpsCount(): int

Tests/DataCollector/DumpDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testDump()
6060
$this->assertSame(0, $collector->getDumpsCount());
6161

6262
$serialized = serialize($collector);
63-
$this->assertSame("O:60:\"Symfony\Component\HttpKernel\DataCollector\DumpDataCollector\":1:{s:7:\"\0*\0data\";a:2:{i:0;b:0;i:1;s:5:\"UTF-8\";}}", $serialized);
63+
$this->assertSame("O:60:\"Symfony\Component\HttpKernel\DataCollector\DumpDataCollector\":1:{s:4:\"data\";a:2:{i:0;b:0;i:1;s:5:\"UTF-8\";}}", $serialized);
6464

6565
$this->assertInstanceOf(DumpDataCollector::class, unserialize($serialized));
6666
}

0 commit comments

Comments
 (0)