Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 994a8bd

Browse files
feature #61424 [HttpKernel][Mime][Serializer][String][Validator] Replace __sleep/wakeup() by __(un)serialize() (nicolas-grekas)
This PR was merged into the 8.0 branch. Discussion ---------- [HttpKernel][Mime][Serializer][String][Validator] Replace `__sleep/wakeup()` by `__(un)serialize()` | Q | A | ------------- | --- | Branch? | 8.0 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #61407 | License | MIT This gets rid of all usages of `__sleep/wakeup()` while preserving FC/BC for payloads. Commits ------- 2b841c1 [HttpKernel][Mime][Serializer][String][Validator] Replace `__sleep/wakeup()` by `__(un)serialize()`
2 parents 781c584 + 2b841c1 commit 994a8bd

21 files changed

+146
-834
lines changed

UPGRADE-8.0.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ HttpKernel
200200
* Remove `Kernel::getAnnotatedClassesToCompile()` and `Kernel::setAnnotatedClassCache()`
201201
* Make `ServicesResetter` class `final`
202202
* Add argument `$logChannel` to `ErrorListener::logException()`
203+
* Replace `__sleep/wakeup()` by `__(un)serialize()` on kernels and data collectors
203204

204205
Intl
205206
----
@@ -224,6 +225,11 @@ Messenger
224225
* Remove `text` format when using the `messenger:stats` command
225226
* Add method `getRetryDelay()` to `RecoverableExceptionInterface`
226227

228+
Mime
229+
----
230+
231+
* Replace `__sleep/wakeup()` by `__(un)serialize()` on `AbstractPart` implementations
232+
227233
Notifier
228234
--------
229235

@@ -464,6 +470,11 @@ Translation
464470
* Make `DataCollectorTranslator` class `final`
465471
* Remove `ProviderFactoryTestCase`, extend `AbstractProviderFactoryTestCase` instead
466472

473+
String
474+
------
475+
476+
* Replace `__sleep/wakeup()` by `__(un)serialize()` on string implementations
477+
467478
TwigBridge
468479
----------
469480

@@ -498,6 +509,7 @@ Validator
498509
---------
499510

500511
* Add method `getGroupProvider()` to `ClassMetadataInterface`
512+
* Replace `__sleep/wakeup()` by `__(un)serialize()` on `GenericMetadata` implementations
501513
* Remove the `getRequiredOptions()` and `getDefaultOption()` methods from the `All`, `AtLeastOneOf`, `CardScheme`, `Collection`,
502514
`CssColor`, `Expression`, `Regex`, `Sequentially`, `Type`, and `When` constraints
503515
* Remove support for evaluating options in the base `Constraint` class. Initialize properties in the constructor of the concrete constraint

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
* Remove `Kernel::getAnnotatedClassesToCompile()` and `Kernel::setAnnotatedClassCache()`
1010
* Make `ServicesResetter` class `final`
1111
* Add argument `$logChannel` to `ErrorListener::logException()`
12+
* Replace `__sleep/wakeup()` by `__(un)serialize()` on kernels and data collectors
1213

1314
7.4
1415
---

src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -86,71 +86,12 @@ protected function getCasters(): array
8686

8787
public function __serialize(): array
8888
{
89-
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) {
90-
return ['data' => $this->data];
91-
}
92-
93-
trigger_deprecation('symfony/http-kernel', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
94-
95-
$data = [];
96-
foreach ($this->__sleep() as $key) {
97-
try {
98-
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
99-
$data[$key] = $r->getValue($this);
100-
}
101-
} catch (\ReflectionException) {
102-
$data[$key] = $this->$key;
103-
}
104-
}
105-
106-
return $data;
89+
return ['data' => $this->data];
10790
}
10891

10992
public function __unserialize(array $data): void
11093
{
111-
if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
112-
trigger_deprecation('symfony/http-kernel', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
113-
}
114-
115-
if (\in_array(array_keys($data), [['data'], ["\0*\0data"]], true)) {
116-
$this->data = $data['data'] ?? $data["\0*\0data"];
117-
118-
if ($wakeup) {
119-
$this->__wakeup();
120-
}
121-
122-
return;
123-
}
124-
125-
trigger_deprecation('symfony/http-kernel', '7.4', 'Passing more than just key "data" to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
126-
127-
\Closure::bind(function ($data) use ($wakeup) {
128-
foreach ($data as $key => $value) {
129-
$this->{("\0" === $key[0] ?? '') ? substr($key, 1 + strrpos($key, "\0")) : $key} = $value;
130-
}
131-
132-
if ($wakeup) {
133-
$this->__wakeup();
134-
}
135-
}, $this, static::class)($data);
136-
}
137-
138-
/**
139-
* @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0
140-
*/
141-
public function __sleep(): array
142-
{
143-
trigger_deprecation('symfony/http-kernel', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
144-
145-
return ['data'];
146-
}
147-
148-
/**
149-
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
150-
*/
151-
public function __wakeup(): void
152-
{
153-
trigger_deprecation('symfony/http-kernel', '7.4', 'Calling "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
94+
$this->data = $data['data'] ?? $data["\0*\0data"];
15495
}
15596

15697
public function reset(): void

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 11 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -751,95 +751,24 @@ private function preBoot(): ContainerInterface
751751

752752
public function __serialize(): array
753753
{
754-
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) {
755-
return [
756-
'environment' => $this->environment,
757-
'debug' => $this->debug,
758-
];
759-
}
760-
761-
trigger_deprecation('symfony/http-kernel', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
762-
763-
$data = [];
764-
foreach ($this->__sleep() as $key) {
765-
try {
766-
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
767-
$data[$key] = $r->getValue($this);
768-
}
769-
} catch (\ReflectionException) {
770-
$data[$key] = $this->$key;
771-
}
772-
}
773-
774-
return $data;
754+
return [
755+
'environment' => $this->environment,
756+
'debug' => $this->debug,
757+
];
775758
}
776759

777760
public function __unserialize(array $data): void
778761
{
779-
if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
780-
trigger_deprecation('symfony/http-kernel', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
781-
}
782-
783-
if (\in_array(array_keys($data), [['environment', 'debug'], ["\0*\0environment", "\0*\0debug"]], true)) {
784-
$environment = $data['environment'] ?? $data["\0*\0environment"];
785-
$debug = $data['debug'] ?? $data["\0*\0debug"];
786-
787-
if (\is_object($environment) || \is_object($debug)) {
788-
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
789-
}
790-
791-
$this->environment = $environment;
792-
$this->debug = $debug;
793-
794-
if ($wakeup) {
795-
$this->__wakeup();
796-
} else {
797-
$this->__construct($environment, $debug);
798-
}
799-
800-
return;
801-
}
802-
803-
trigger_deprecation('symfony/http-kernel', '7.4', 'Passing more than just key "environment" and "debug" to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
804-
805-
\Closure::bind(function ($data) use ($wakeup) {
806-
foreach ($data as $key => $value) {
807-
$this->{("\0" === $key[0] ?? '') ? substr($key, 1 + strrpos($key, "\0")) : $key} = $value;
808-
}
809-
810-
if ($wakeup) {
811-
$this->__wakeup();
812-
} else {
813-
if (\is_object($this->environment) || \is_object($this->debug)) {
814-
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
815-
}
816-
817-
$this->__construct($this->environment, $this->debug);
818-
}
819-
}, $this, static::class)($data);
820-
}
821-
822-
/**
823-
* @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0
824-
*/
825-
public function __sleep(): array
826-
{
827-
trigger_deprecation('symfony/http-kernel', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
828-
829-
return ['environment', 'debug'];
830-
}
831-
832-
/**
833-
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
834-
*/
835-
public function __wakeup(): void
836-
{
837-
trigger_deprecation('symfony/http-kernel', '7.4', 'Calling "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
762+
$environment = $data['environment'] ?? $data["\0*\0environment"];
763+
$debug = $data['debug'] ?? $data["\0*\0debug"];
838764

839-
if (\is_object($this->environment) || \is_object($this->debug)) {
765+
if (\is_object($environment) || \is_object($debug)) {
840766
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
841767
}
842768

843-
$this->__construct($this->environment, $this->debug);
769+
$this->environment = $environment;
770+
$this->debug = $debug;
771+
772+
$this->__construct($environment, $debug);
844773
}
845774
}

src/Symfony/Component/HttpKernel/Profiler/Profile.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @author Fabien Potencier <[email protected]>
1818
*
19-
* @final since Symfony 7.4
19+
* @final
2020
*/
2121
class Profile
2222
{
@@ -248,11 +248,19 @@ public function hasCollector(string $name): bool
248248
return isset($this->collectors[$name]);
249249
}
250250

251-
/**
252-
* @internal since Symfony 7.4, will be replaced by `__serialize()` in 8.0
253-
*/
254-
public function __sleep(): array
251+
public function __serialize(): array
255252
{
256-
return ['token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode', 'virtualType'];
253+
return [
254+
'token' => $this->token,
255+
'parent' => $this->parent,
256+
'children' => $this->children,
257+
'collectors' => $this->collectors,
258+
'ip' => $this->ip,
259+
'method' => $this->method,
260+
'url' => $this->url,
261+
'time' => $this->time,
262+
'statusCode' => $this->statusCode,
263+
'virtualType' => $this->virtualType,
264+
];
257265
}
258266
}

src/Symfony/Component/Mime/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 `AbstractPart` implementations
8+
49
7.4
510
---
611

src/Symfony/Component/Mime/Part/AbstractPart.php

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -65,52 +65,11 @@ abstract public function getMediaSubtype(): string;
6565

6666
public function __serialize(): array
6767
{
68-
if (!method_exists($this, '__sleep')) {
69-
return ['headers' => $this->headers];
70-
}
71-
72-
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
73-
74-
$data = [];
75-
foreach ($this->__sleep() as $key) {
76-
try {
77-
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
78-
$data[$key] = $r->getValue($this);
79-
}
80-
} catch (\ReflectionException) {
81-
$data[$key] = $this->$key;
82-
}
83-
}
84-
85-
return $data;
68+
return ['headers' => $this->headers];
8669
}
8770

8871
public function __unserialize(array $data): void
8972
{
90-
if ($wakeup = method_exists($this, '__wakeup') && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
91-
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
92-
}
93-
94-
if (['headers'] === array_keys($data)) {
95-
$this->headers = $data['headers'];
96-
97-
if ($wakeup) {
98-
$this->__wakeup();
99-
}
100-
101-
return;
102-
}
103-
104-
trigger_deprecation('symfony/mime', '7.4', 'Passing more than just key "headers" to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
105-
106-
\Closure::bind(function ($data) use ($wakeup) {
107-
foreach ($data as $key => $value) {
108-
$this->{("\0" === $key[0] ?? '') ? substr($key, 1 + strrpos($key, "\0")) : $key} = $value;
109-
}
110-
111-
if ($wakeup) {
112-
$this->__wakeup();
113-
}
114-
}, $this, static::class)($data);
73+
$this->headers = $data['headers'];
11574
}
11675
}

0 commit comments

Comments
 (0)