Skip to content

Commit b875dfb

Browse files
Merge branch '7.3' into 7.4
* 7.3: Replace __sleep/wakeup() by __(un)serialize() for throwing and internal usages [TypeInfo] simplify identifier comparison in isIdentifiedBy method
2 parents 2e0fcc3 + f68e3f5 commit b875dfb

File tree

17 files changed

+198
-189
lines changed

17 files changed

+198
-189
lines changed

src/Symfony/Component/ErrorHandler/ErrorRenderer/FileLinkFormatter.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ public function format(string $file, int $line): string|false
6262
return false;
6363
}
6464

65-
/**
66-
* @internal
67-
*/
6865
public function __serialize(): array
6966
{
7067
$this->fileLinkFormat = $this->getFileLinkFormat();

src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ public function getData(): array|Data
197197
return $this->data;
198198
}
199199

200-
/**
201-
* @internal
202-
*/
203200
public function __serialize(): array
204201
{
205202
foreach ($this->data['forms_by_hash'] as &$form) {

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

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

146-
/**
147-
* @internal
148-
*/
149146
public function __serialize(): array
150147
{
151148
if (!$this->dataCount) {
@@ -164,9 +161,6 @@ public function __serialize(): array
164161
return ['data' => $this->data];
165162
}
166163

167-
/**
168-
* @internal
169-
*/
170164
public function __unserialize(array $data): void
171165
{
172166
$this->data = array_pop($data) ?? [];

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

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -59,75 +59,12 @@ public function bodyToIterable(): iterable
5959

6060
public function __serialize(): array
6161
{
62-
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) {
63-
return ['message' => $this->message];
64-
}
65-
66-
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
67-
68-
$data = [];
69-
foreach ($this->__sleep() as $key) {
70-
try {
71-
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
72-
$data[$key] = $r->getValue($this);
73-
}
74-
} catch (\ReflectionException) {
75-
$data[$key] = $this->$key;
76-
}
77-
}
78-
79-
return $data;
62+
return ['message' => $this->message];
8063
}
8164

8265
public function __unserialize(array $data): void
8366
{
84-
if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
85-
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
86-
}
87-
88-
if (\in_array(array_keys($data), [['message'], ["\0".self::class."\0message"]], true)) {
89-
$this->message = $data['message'] ?? $data["\0".self::class."\0message"];
90-
91-
if ($wakeup) {
92-
$this->__wakeup();
93-
} else {
94-
$this->__construct($this->message);
95-
}
96-
97-
return;
98-
}
99-
100-
trigger_deprecation('symfony/mime', '7.4', 'Passing more than just key "message" to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
101-
102-
\Closure::bind(function ($data) use ($wakeup) {
103-
foreach ($data as $key => $value) {
104-
$this->{("\0" === $key[0] ?? '') ? substr($key, 1 + strrpos($key, "\0")) : $key} = $value;
105-
}
106-
107-
if ($wakeup) {
108-
$this->__wakeup();
109-
} else {
110-
$this->__construct($this->message);
111-
}
112-
}, $this, static::class)($data);
113-
}
114-
115-
/**
116-
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
117-
*/
118-
public function __sleep(): array
119-
{
120-
trigger_deprecation('symfony/mime', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
121-
122-
return ['message'];
123-
}
124-
125-
/**
126-
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
127-
*/
128-
public function __wakeup(): void
129-
{
130-
trigger_deprecation('symfony/mime', '7.4', 'Calling "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
67+
$this->message = $data['message'] ?? $data["\0".self::class."\0message"];
13168

13269
$this->__construct($this->message);
13370
}

src/Symfony/Component/TypeInfo/Type/BuiltinType.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,7 @@ public function getTypeIdentifier(): TypeIdentifier
4141
public function isIdentifiedBy(TypeIdentifier|string ...$identifiers): bool
4242
{
4343
foreach ($identifiers as $identifier) {
44-
if (\is_string($identifier)) {
45-
try {
46-
$identifier = TypeIdentifier::from($identifier);
47-
} catch (\ValueError) {
48-
continue;
49-
}
50-
}
51-
52-
if ($identifier === $this->typeIdentifier) {
44+
if ($identifier === $this->typeIdentifier || $identifier === $this->typeIdentifier->value) {
5345
return true;
5446
}
5547
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarExporter\Tests\Fixtures;
13+
14+
class GoodNight
15+
{
16+
public $good;
17+
protected $foo;
18+
private $bar;
19+
20+
public function __construct()
21+
{
22+
unset($this->good);
23+
$this->foo = 'afternoon';
24+
$this->bar = 'morning';
25+
}
26+
27+
public function __sleep(): array
28+
{
29+
$this->good = 'night';
30+
31+
return ['good', 'foo', "\0*\0foo", "\0".__CLASS__."\0bar"];
32+
}
33+
}

src/Symfony/Component/VarExporter/Tests/Fixtures/LazyGhost/MagicClass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __get($name)
2727
return $this->data[$name] ?? null;
2828
}
2929

30-
public function __set($name, $value)
30+
public function __set($name, $value): void
3131
{
3232
$this->data[$name] = $value;
3333
}
@@ -37,7 +37,7 @@ public function __isset($name): bool
3737
return isset($this->data[$name]);
3838
}
3939

40-
public function __unset($name)
40+
public function __unset($name): void
4141
{
4242
unset($this->data[$name]);
4343
}

src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/TestWakeupClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class TestWakeupClass extends TestClass
1515
{
16-
public function __wakeup()
16+
public function __wakeup(): void
1717
{
1818
$this->dep->wokeUp = true;
1919
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarExporter\Tests\Fixtures;
13+
14+
class MyWakeup
15+
{
16+
public $sub;
17+
public $bis;
18+
public $baz;
19+
public $def = 234;
20+
21+
public function __sleep(): array
22+
{
23+
return ['sub', 'baz'];
24+
}
25+
26+
public function __wakeup(): void
27+
{
28+
if (123 === $this->sub) {
29+
$this->bis = 123;
30+
$this->baz = 123;
31+
}
32+
}
33+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarExporter\Tests\Fixtures;
13+
14+
class Php74Serializable implements \Serializable
15+
{
16+
public $foo;
17+
18+
public function __serialize(): array
19+
{
20+
return [$this->foo = new \stdClass()];
21+
}
22+
23+
public function __unserialize(array $data): void
24+
{
25+
[$this->foo] = $data;
26+
}
27+
28+
public function __sleep(): array
29+
{
30+
throw new \BadMethodCallException();
31+
}
32+
33+
public function __wakeup(): void
34+
{
35+
throw new \BadMethodCallException();
36+
}
37+
38+
public function serialize(): string
39+
{
40+
throw new \BadMethodCallException();
41+
}
42+
43+
public function unserialize($ser)
44+
{
45+
throw new \BadMethodCallException();
46+
}
47+
}

0 commit comments

Comments
 (0)