8000 feature #30051 Drop \Serializable implementations (renanbr) · symfony/symfony@98693be · GitHub
[go: up one dir, main page]

Skip to content

Commit 98693be

Browse files
feature #30051 Drop \Serializable implementations (renanbr)
This PR was merged into the 4.3-dev branch. Discussion ---------- Drop \Serializable implementations | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes, it removes `\Serializable` interface from many classes | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a This PR replaces [Serializable](https://secure.php.net/serializable) implementations with [__sleep() and __wakeup()](http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep). Changes touch these components: - Config - DependencyInjection - Form - HttpKernel - Validator Commits ------- f8bf973 Drop \Serializable
2 parents bb59924 + f8bf973 commit 98693be

16 files changed

+51
-154
lines changed

src/Symfony/Component/Config/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* deprecated using environment variables with `cannotBeEmpty()` if the value is validated with `validate()`
8+
* made `Resource\*` classes final and not implement `Serializable` anymore
89

910
4.2.0
1011
-----

src/Symfony/Component/Config/Resource/ClassExistenceResource.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
* The resource must be a fully-qualified class name.
1919
*
2020
* @author Fabien Potencier <fabien@symfony.com>
21+
*
22+
* @final since Symfony 4.3
2123
*/
22-
class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializable
24+
class ClassExistenceResource implements SelfCheckingResourceInterface
2325
{
2426
private $resource;
2527
private $exists;
@@ -97,21 +99,13 @@ public function isFresh($timestamp)
9799
/**
98100
* @internal
99101
*/
100-
public function serialize()
102+
public function __sleep(): array
101103
{
102104
if (null === $this->exists) {
103105
$this->isFresh(0);
104106
}
105107

106-
return serialize([$this->resource, $this->exists]);
107-
}
108-
109-
/**
110-
* @internal
111-
*/
112-
public function unserialize($serialized)
113-
{
114-
list($this->resource, $this->exists) = unserialize($serialized);
108+
return ['resource', 'exists'];
115109
}
116110

117111
/**

src/Symfony/Component/Config/Resource/ComposerResource.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
* ComposerResource tracks the PHP version and Composer dependencies.
1616
*
1717
* @author Nicolas Grekas <p@tchwork.com>
18+
*
19+
* @final since Symfony 4.3
1820
*/
19-
class ComposerResource implements SelfCheckingResourceInterface, \Serializable
21+
class ComposerResource implements SelfCheckingResourceInterface
2022
{
2123
private $vendors;
2224

@@ -51,22 +53,6 @@ public function isFresh($timestamp)
5153
return self::$runtimeVendors === $this->vendors;
5254
}
5355

54-
/**
55-
* @internal
56-
*/
57-
public function serialize()
58-
{
59-
return serialize($this->vendors);
60-
}
61-
62-
/**
63-
* @internal
64-
*/
65-
public function unserialize($serialized)
66-
{
67-
$this->vendors = unserialize($serialized);
68-
}
69-
7056
private static function refresh()
7157
{
7258
self::$runtimeVendors = [];

src/Symfony/Component/Config/Resource/DirectoryResource.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
* DirectoryResource represents a resources stored in a subdirectory tree.
1616
*
1717
* @author Fabien Potencier <fabien@symfony.com>
18+
*
19+
* @final since Symfony 4.3
1820
*/
19-
class DirectoryResource implements SelfCheckingResourceInterface, \Serializable
21+
class DirectoryResource implements SelfCheckingResourceInterface
2022
{
2123
private $resource;
2224
private $pattern;
@@ -103,20 +105,4 @@ public function isFresh($timestamp)
103105

104106
return true;
105107
}
106-
107-
/**
108-
* @internal
109-
*/
110-
public function serialize()
111-
{
112-
return serialize([$this->resource, $this->pattern]);
113-
}
114-
115-
/**
116-
* @internal
117-
*/
118-
public function unserialize($serialized)
119-
{
120-
list($this->resource, $this->pattern) = unserialize($serialized);
121-
}
122108
}

src/Symfony/Component/Config/Resource/FileExistenceResource.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
* The resource can be a file or a directory.
1919
*
2020
* @author Charles-Henri Bruyand <charleshenri.bruyand@gmail.com>
21+
*
22+
* @final since Symfony 4.3
2123
*/
22-
class FileExistenceResource implements SelfCheckingResourceInterface, \Serializable
24+
class FileExistenceResource implements SelfCheckingResourceInterface
2325
{
2426
private $resource;
2527

@@ -57,20 +59,4 @@ public function isFresh($timestamp)
5759
{
5860
return file_exists($this->resource) === $this->exists;
5961
}
60-
61-
/**
62-
* @internal
63-
*/
64-
public function serialize()
65-
{
66-
return serialize([$this->resource, $this->exists]);
67-
}
68-
69-
/**
70-
* @internal
71-
*/
72-
public function unserialize($serialized)
73-
{
74-
list($this->resource, $this->exists) = unserialize($serialized);
75-
}
7662
}

src/Symfony/Component/Config/Resource/FileResource.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
* The resource can be a file or a directory.
1818
*
1919
* @author Fabien Potencier <fabien@symfony.com>
20+
*
21+
* @final since Symfony 4.3
2022
*/
21-
class FileResource implements SelfCheckingResourceInterface, \Serializable
23+
class FileResource implements SelfCheckingResourceInterface
2224
{
2325
/**
2426
* @var string|false
@@ -62,20 +64,4 @@ public function isFresh($timestamp)
6264
{
6365
return false !== ($filemtime = @filemtime($this->resource)) && $filemtime <= $timestamp;
6466
}
65-
66-
/**
67-
* @internal
68-
*/
69-
publi 1241 c function serialize()
70-
{
71-
return serialize($this->resource);
72-
}
73-
74-
/**
75-
* @internal
76-
*/
77-
public function unserialize($serialized)
78-
{
79-
$this->resource = unserialize($serialized);
80-
}
8167
}

src/Symfony/Component/Config/Resource/GlobResource.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
* Only existence/removal is tracked (not mtimes.)
2121
*
2222
* @author Nicolas Grekas <p@tchwork.com>
23+
*
24+
* @final since Symfony 4.3
2325
*/
24-
class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface, \Serializable
26+
class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface
2527
{
2628
private $prefix;
2729
private $pattern;
@@ -80,21 +82,13 @@ public function isFresh($timestamp)
8082
/**
8183
* @internal
8284
*/
83-
public function serialize()
85+
public function __sleep(): array
8486
{
8587
if (null === $this->hash) {
8688
$this->hash = $this->computeHash();
8789
}
8890

89-
return serialize([$this->prefix, $this->pattern, $this->recursive, $this->hash, $this->forExclusion, $this->excludedPrefixes]);
90-
}
91-
92-
/**
93-
* @internal
94-
*/
95-
public function unserialize($serialized)
96-
{
97-
list($this->prefix, $this->pattern, $this->recursive, $this->hash, $this->forExclusion, $this->excludedPrefixes) = unserialize($serialized) + [4 => false, []];
91+
return ['prefix', 'pattern', 'recursive', 'hash', 'forExclusion', 'excludedPrefixes'];
9892
}
9993

10094
public function getIterator()

src/Symfony/Component/Config/Resource/ReflectionClassResource.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
/**
1919
* @author Nicolas Grekas <p@tchwork.com>
20+
*
21+
* @final since Symfony 4.3
2022
*/
21-
class ReflectionClassResource implements SelfCheckingResourceInterface, \Serializable
23+
class ReflectionClassResource implements SelfCheckingResourceInterface
2224
{
2325
private $files = [];
2426
private $className;
@@ -61,22 +63,14 @@ public function __toString()
6163
/**
6264
* @internal
6365
*/
64-
public function serialize()
66+
public function __sleep(): array
6567
{
6668
if (null === $this->hash) {
6769
$this->hash = $this->computeHash();
6870
$this->loadFiles($this->classReflector);
6971
}
7072

71-
return serialize([$this->files, $this->className, $this->hash]);
72-
}
73-
74-
/**
75-
* @internal
76-
*/
77-
public function unserialize($serialized)
78-
{
79-
list($this->files, $this->className, $this->hash) = unserialize($serialized);
73+
return ['files', 'className', 'hash'];
8074
}
8175

8276
private function loadFiles(\ReflectionClass $class)

src/Symfony/Component/Config/ResourceCheckerConfigCache.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private function safelyUnserialize($file)
158158
$meta = false;
159159
$content = file_get_contents($file);
160160
$signalingException = new \UnexpectedValueException();
161-
$prevUnserializeHandler = ini_set('unserialize_callback_func', '');
161+
$prevUnserializeHandler = ini_set('unserialize_callback_func', self::class.'::handleUnserializeCallback');
162162
$prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$prevErrorHandler, $signalingException) {
163163
if (__FILE__ === $file) {
164164
throw $signalingException;
@@ -180,4 +180,12 @@ private function safelyUnserialize($file)
180180

181181
return $meta;
182182
}
183+
184+
/**
185+
* @internal
186+
*/
187+
public static function handleUnserializeCallback($class)
188+
{
189+
trigger_error('Class not found: '.$class);
190+
}
183191
}

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* added `%env(default:...)%` processor to fallback to a default value
99
* added `%env(nullable:...)%` processor to allow empty variables to be processed as null values
1010
* added support for deprecating aliases
11+
* made `ContainerParametersResource` final and not implement `Serializable` anymore
1112

1213
4.2.0
1314
-----

src/Symfony/Component/DependencyInjection/Config/ContainerParametersResource.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
* Tracks container parameters.
1818
*
1919
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
20+
*
21+
* @final since Symfony 4.3
2022
*/
21-
class ContainerParametersResource implements ResourceInterface, \Serializable
23+
class ContainerParametersResource implements ResourceInterface
2224
{
2325
private $parameters;
2426

@@ -38,22 +40,6 @@ public function __toString()
3840
return 'container_parameters_'.md5(serialize($this->parameters));
3941
}
4042

41-
/**
42-
* @internal
43-
*/
44-
public function serialize()
45-
{
46-
return serialize($this->parameters);
47-
}
48-
49-
/**
50-
* @internal
51-
*/
52-
public function unserialize($serialized)
53-
{
54-
$this->parameters = unserialize($serialized);
55-
}
56-
5743
/**
5844
* @return array Tracked parameters
5945
*/

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
option is set to `single_text`
99
* added `block_prefix` option to `BaseType`.
1010
* added `help_html` option to display the `help` text as HTML.
11+
* `FormError` doesn't implement `Serializable` anymore
1112
* added `label_translation_parameters`, `attr_translation_parameters`, `help_translation_parameters` options
1213
to `FormType` to pass translation parameters to form labels, attributes (`placeholder` and `title`) and help text respectively.
1314
The passed parameters will replace placeholders in translation messages.
@@ -32,7 +33,6 @@ CHANGELOG
3233
}
3334
```
3435

35-
3636
4.2.0
3737
-----
3838

src/Symfony/Component/Form/FormError.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Bernhard Schussek <bschussek@gmail.com>
2020
*/
21-
class FormError implements \Serializable
21+
class FormError
2222
{
2323
protected $messageTemplate;
2424
protected $messageParameters;
@@ -133,26 +133,4 @@ public function getOrigin()
133133
{
134134
return $this->origin;
135135
}
136-
137-
/**
138-
* @internal
139-
*/
140-
public function serialize()
141-
{
142-
return serialize([
143-
$this->message,
144-
$this->messageTemplate,
145-
$this->messageParameters,
146-
$this->messagePluralization,
147-
$this->cause,
148-
]);
149-
}
150-
151-
/**
152-
* @internal
153-
*/
154-
public function unserialize($serialized)
155-
{
156-
list($this->message, $this->messageTemplate, $this->messageParameters, $this->messagePluralization, $this->cause) = unserialize($serialized, ['allowed_classes' => false]);
157-
}
158136
}

src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ public function testSerializeWithFormAddedMultipleTimes()
448448
$this->dataCollector->collectViewVariables($form2View);
449449
$this->dataCollector->buildFinalFormTree($form2, $form2View);
450450

451-
$this->dataCollector->serialize();
451+
serialize($this->dataCollector);
452452
}
453453

454454
public function testFinalFormReliesOnFormViewStructure()

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* increased the priority of `Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener`
88
* made `Symfony\Component\HttpKernel\EventListenerLocaleListener` set the default locale early
9+
* made `FileLinkFormatter` final and not implement `Serializable` anymore
910

1011
4.2.0
1112
-----

0 commit comments

Comments
 (0)
0