Skip to content

Commit d7b049d

Browse files
[HttpKernel][Mime][Serializer][String][Validator] Replace __sleep/wakeup() by __(un)serialize()
1 parent 86ca954 commit d7b049d

File tree

4 files changed

+8
-101
lines changed

4 files changed

+8
-101
lines changed

AbstractString.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -708,34 +708,7 @@ public function wordwrap(int $width = 75, string $break = "\n", bool $cut = fals
708708

709709
public function __serialize(): array
710710
{
711-
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) {
712-
return ['string' => $this->string];
713-
}
714-
715-
trigger_deprecation('symfony/string', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
716-
717-
$data = [];
718-
foreach ($this->__sleep() as $key) {
719-
try {
720-
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
721-
$data[$key] = $r->getValue($this);
722-
}
723-
} catch (\ReflectionException) {
724-
$data[$key] = $this->$key;
725-
}
726-
}
727-
728-
return $data;
729-
}
730-
731-
/**
732-
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
733-
*/
734-
public function __sleep(): array
735-
{
736-
trigger_deprecation('symfony/string', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
737-
738-
return ['string'];
711+
return ['string' => $this->string];
739712
}
740713

741714
public function __clone()

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
8.0
5+
---
6+
7+
* Replace `__sleep/wakeup()` by `__(un)serialize()` on string implementations
8+
49
7.4
510
---
611

LazyString.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -103,38 +103,9 @@ public function __toString(): string
103103

104104
public function __serialize(): array
105105
{
106-
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) {
107-
$this->__toString();
108-
109-
return ['value' => $this->value];
110-
}
111-
112-
trigger_deprecation('symfony/string', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
113-
114-
$data = [];
115-
foreach ($this->__sleep() as $key) {
116-
try {
117-
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
118-
$data[$key] = $r->getValue($this);
119-
}
120-
} catch (\ReflectionException) {
121-
$data[$key] = $this->$key;
122-
}
123-
}
124-
125-
return $data;
126-
}
127-
128-
/**
129-
* @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0
130-
*/
131-
public function __sleep(): array
132-
{
133-
trigger_deprecation('symfony/string', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
134-
135106
$this->__toString();
136107

137-
return ['value'];
108+
return ['value' => $this->value];
138109
}
139110

140111
public function jsonSerialize(): string

UnicodeString.php

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -368,49 +368,7 @@ public function startsWith(string|iterable|AbstractString $prefix): bool
368368

369369
public function __unserialize(array $data): void
370370
{
371-
if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
372-
trigger_deprecation('symfony/string', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
373-
}
374-
375-
try {
376-
if (\in_array(array_keys($data), [['string'], ["\0*\0string"]], true)) {
377-
$this->string = $data['string'] ?? $data["\0*\0string"];
378-
379-
if ($wakeup) {
380-
$this->__wakeup();
381-
}
382-
383-
return;
384-
}
385-
386-
trigger_deprecation('symfony/string', '7.4', 'Passing more than just key "string" to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
387-
388-
\Closure::bind(function ($data) use ($wakeup) {
389-
foreach ($data as $key => $value) {
390-
$this->{("\0" === $key[0] ?? '') ? substr($key, 1 + strrpos($key, "\0")) : $key} = $value;
391-
}
392-
393-
if ($wakeup) {
394-
$this->__wakeup();
395-
}
396-
}, $this, static::class)($data);
397-
} finally {
398-
if (!$wakeup) {
399-
if (!\is_string($this->string)) {
400-
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
401-
}
402-
403-
normalizer_is_normalized($this->string) ?: $this->string = normalizer_normalize($this->string);
404-
}
405-
}
406-
}
407-
408-
/**
409-
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
410-
*/
411-
public function __wakeup(): void
412-
{
413-
trigger_deprecation('symfony/string', '7.4', 'Calling "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
371+
$this->string = $data['string'] ?? $data["\0*\0string"];
414372

415373
if (!\is_string($this->string)) {
416374
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);

0 commit comments

Comments
 (0)