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

Skip to content

Commit 05d6475

Browse files
Drop more usages of Serializable
1 parent ec8033f commit 05d6475

File tree

27 files changed

+216
-114
lines changed

27 files changed

+216
-114
lines changed

UPGRADE-4.3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Routing
5555

5656
* The `generator_base_class`, `generator_cache_class`, `matcher_base_class`, and `matcher_cache_class` router
5757
options have been deprecated.
58+
* Implementing `Serializable` for `Route` and `CompiledRoute` is deprecated; if you serialize them, please
59+
ensure your unserialization logic can recover from a failure related to an updated serialization format
5860

5961
Security
6062
--------

UPGRADE-5.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ Routing
234234

235235
* The `generator_base_class`, `generator_cache_class`, `matcher_base_class`, and `matcher_cache_class` router
236236
options have been removed.
237+
* `Route` and `CompiledRoute` don't implement `Serializable` anymore; if you serialize them, please
238+
ensure your unserialization logic can recover from a failure related to an updated serialization format
237239

238240
Security
239241
--------

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,14 @@ protected function build(ContainerBuilder $container)
7979
$container->register('logger', NullLogger::class);
8080
}
8181

82-
public function serialize()
82+
public function __sleep()
8383
{
84-
return serialize([$this->varDir, $this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()]);
84+
return ['varDir', 'testCase', 'rootConfig', 'environment', 'debug'];
8585
}
8686

87-
public function unserialize($str)
87+
public function __wakeup()
8888
{
89-
$a = unserialize($str);
90-
$this->__construct($a[0], $a[1], $a[2], $a[3], $a[4]);
89+
$this->__construct($this->varDir, $this->testCase, $this->rootConfig, $this->environment, $this->debug);
9190
}
9291

9392
protected function getKernelParameters()

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"symfony/dependency-injection": "^4.3",
2525
"symfony/event-dispatcher": "^4.1",
2626
"symfony/http-foundation": "^4.3",
27-
"symfony/http-kernel": "^4.2",
27+
"symfony/http-kernel": "^4.3",
2828
"symfony/polyfill-mbstring": "~1.0",
2929
"symfony/filesystem": "~3.4|~4.0",
3030
"symfony/finder": "~3.4|~4.0",

src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,9 @@ public function testPrune()
215215
}
216216
}
217217

218-
class NotUnserializable implements \Serializable
218+
class NotUnserializable
219219
{
220-
public function serialize()
221-
{
222-
return serialize(123);
223-
}
224-
225-
public function unserialize($ser)
220+
public function __wakeup()
226221
{
227222
throw new \Exception(__CLASS__);
228223
}

src/Symfony/Component/Cache/Tests/Psr16CacheTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,9 @@ protected function isPruned($cache, $name)
159159
}
160160
}
161161

162-
class NotUnserializable implements \Serializable
162+
class NotUnserializable
163163
{
164-
public function serialize()
165-
{
166-
return serialize(123);
167-
}
168-
169-
public function unserialize($ser)
164+
public function __wakeup()
170165
{
171166
throw new \Exception(__CLASS__);
172167
}

src/Symfony/Component/Cache/Tests/Simple/CacheTestCase.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,9 @@ public function testPrune()
132132
}
133133
}
134134

135-
class NotUnserializable implements \Serializable
135+
class NotUnserializable
136136
{
137-
public function serialize()
138-
{
139-
return serialize(123);
140-
}
141-
142-
public function unserialize($ser)
137+
public function __wakeup()
143138
{
144139
throw new \Exception(__CLASS__);
145140
}

src/Symfony/Component/Debug/Tests/phpt/fatal_with_nested_handlers.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var_dump([
2424
$eHandler[0]->setExceptionHandler('print_r');
2525

2626
if (true) {
27-
class Broken implements \Serializable
27+
class Broken implements \JsonSerializable
2828
{
2929
}
3030
}
@@ -37,6 +37,6 @@ array(1) {
3737
}
3838
object(Symfony\Component\Debug\Exception\FatalErrorException)#%d (%d) {
3939
["message":protected]=>
40-
string(199) "Error: Class Symfony\Component\Debug\Broken contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (Serializable::serialize, Serializable::unserialize)"
40+
string(179) "Error: Class Symfony\Component\Debug\Broken contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (JsonSerializable::jsonSerialize)"
4141
%a
4242
}

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CHANGELOG
1515
* added `block_prefix` option to `BaseType`.
1616
* added `help_html` option to display the `help` text as HTML.
1717
* `FormError` doesn't implement `Serializable` anymore
18+
* `FormDataCollector` has been marked as `final`
1819
* added `label_translation_parameters`, `attr_translation_parameters`, `help_translation_parameters` options
1920
to `FormType` to pass translation parameters to form labels, attributes (`placeholder` and `title`) and help text respectively.
2021
The passed parameters will replace placeholders in translation messages.

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*
2828
* @author Robert Schönthal <[email protected]>
2929
* @author Bernhard Schussek <[email protected]>
30+
*
31+
* @final since Symfony 4.3
3032
*/
3133
class FormDataCollector extends DataCollector implements FormDataCollectorInterface
3234
{
@@ -229,15 +231,20 @@ public function getData()
229231
return $this->data;
230232
}
231233

232-
public function serialize()
234+
/**
235+
* @internal
236+
*/
237+
public function __sleep()
233238
{
234239
foreach ($this->data['forms_by_hash'] as &$form) {
235240
if (isset($form['type_class']) && !$form['type_class'] instanceof ClassStub) {
236241
$form['type_class'] = new ClassStub($form['type_class']);
237242
}
238243
}
239244

240-
return serialize($this->cloneVar($this->data));
245+
$this->data = $this->cloneVar($this->data);
246+
247+
return parent::__sleep();
241248
}
242249

243250
/**

0 commit comments

Comments
 (0)