From 33969158d0758f517a743a2b48211ab6b89e2bea Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 20 May 2021 00:47:05 +0200 Subject: [PATCH] Remove Serializable implementations --- .../Form/Tests/Fixtures/CustomArrayObject.php | 12 +--------- src/Symfony/Component/Mime/CHANGELOG.md | 1 + src/Symfony/Component/Mime/RawMessage.php | 18 +-------------- .../Fixtures/NonTraversableArrayObject.php | 12 +--------- .../Tests/Fixtures/TraversableArrayObject.php | 12 +--------- .../Component/Routing/CompiledRoute.php | 2 +- src/Symfony/Component/Routing/Route.php | 2 +- .../Component/Routing/Tests/RouteTest.php | 2 +- .../Authentication/Token/AbstractToken.php | 4 ++-- .../Core/Authentication/Token/NullToken.php | 21 ------------------ .../Authentication/Token/TokenInterface.php | 2 +- .../Component/Security/Core/CHANGELOG.md | 5 +++++ .../Token/AbstractTokenTest.php | 12 +--------- .../Token/Fixtures/switch-user-token-4.4.txt | Bin 1319 -> 1302 bytes .../Token/SwitchUserTokenTest.php | 2 +- .../Tests/Fixtures/CustomArrayObject.php | 12 +--------- 16 files changed, 19 insertions(+), 100 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php b/src/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php index 5c12b6b400bb8..d210377a5e0b7 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php +++ b/src/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php @@ -15,7 +15,7 @@ * This class is a hand written simplified version of PHP native `ArrayObject` * class, to show that it behaves differently than the PHP native implementation. */ -class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable +class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable { private $array; @@ -63,18 +63,8 @@ public function __serialize(): array return $this->array; } - public function serialize(): string - { - return serialize($this->__serialize()); - } - public function __unserialize(array $data): void { $this->array = $data; } - - public function unserialize($serialized) - { - $this->__unserialize((array) unserialize((string) $serialized)); - } } diff --git a/src/Symfony/Component/Mime/CHANGELOG.md b/src/Symfony/Component/Mime/CHANGELOG.md index fe17b8f0f1122..b076e4e8678a6 100644 --- a/src/Symfony/Component/Mime/CHANGELOG.md +++ b/src/Symfony/Component/Mime/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Remove `Address::fromString()`, use `Address::create()` instead + * Remove `Serializable` interface from `RawMessage` 5.2.0 ----- diff --git a/src/Symfony/Component/Mime/RawMessage.php b/src/Symfony/Component/Mime/RawMessage.php index 66788d8ad526d..b80362587bf8e 100644 --- a/src/Symfony/Component/Mime/RawMessage.php +++ b/src/Symfony/Component/Mime/RawMessage.php @@ -16,7 +16,7 @@ /** * @author Fabien Potencier */ -class RawMessage implements \Serializable +class RawMessage { private $message; @@ -60,22 +60,6 @@ public function ensureValidity() { } - /** - * @internal - */ - final public function serialize(): string - { - return serialize($this->__serialize()); - } - - /** - * @internal - */ - final public function unserialize($serialized) - { - $this->__unserialize(unserialize($serialized)); - } - public function __serialize(): array { return [$this->toString()]; diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php index cf02ee69f2979..fada0fae3b727 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php @@ -15,7 +15,7 @@ * This class is a hand written simplified version of PHP native `ArrayObject` * class, to show that it behaves differently than the PHP native implementation. */ -class NonTraversableArrayObject implements \ArrayAccess, \Countable, \Serializable +class NonTraversableArrayObject implements \ArrayAccess, \Countable { private $array; @@ -58,18 +58,8 @@ public function __serialize(): array return $this->array; } - public function serialize(): string - { - return serialize($this->__serialize()); - } - public function __unserialize(array $data): void { $this->array = $data; } - - public function unserialize($serialized) - { - $this->__unserialize((array) unserialize((string) $serialized)); - } } diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TraversableArrayObject.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TraversableArrayObject.php index 5693c6b73e685..41a2122f8a2e2 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TraversableArrayObject.php +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TraversableArrayObject.php @@ -15,7 +15,7 @@ * This class is a hand written simplified version of PHP native `ArrayObject` * class, to show that it behaves differently than the PHP native implementation. */ -class TraversableArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable +class TraversableArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable { private $array; @@ -63,18 +63,8 @@ public function __serialize(): array return $this->array; } - public function serialize(): string - { - return serialize($this->__serialize()); - } - public function __unserialize(array $data): void { $this->array = $data; } - - public function unserialize($serialized) - { - $this->__unserialize((array) unserialize((string) $serialized)); - } } diff --git a/src/Symfony/Component/Routing/CompiledRoute.php b/src/Symfony/Component/Routing/CompiledRoute.php index 9ffd1b5391c59..c1043b7842869 100644 --- a/src/Symfony/Component/Routing/CompiledRoute.php +++ b/src/Symfony/Component/Routing/CompiledRoute.php @@ -68,7 +68,7 @@ public function __serialize(): array */ final public function serialize(): string { - return serialize($this->__serialize()); + throw new \BadMethodCallException('Cannot serialize '.__CLASS__); } public function __unserialize(array $data): void diff --git a/src/Symfony/Component/Routing/Route.php b/src/Symfony/Component/Routing/Route.php index d52ed4240a8eb..2b3d88cde9ab8 100644 --- a/src/Symfony/Component/Routing/Route.php +++ b/src/Symfony/Component/Routing/Route.php @@ -82,7 +82,7 @@ public function __serialize(): array */ final public function serialize(): string { - return serialize($this->__serialize()); + throw new \BadMethodCallException('Cannot serialize '.__CLASS__); } public function __unserialize(array $data): void diff --git a/src/Symfony/Component/Routing/Tests/RouteTest.php b/src/Symfony/Component/Routing/Tests/RouteTest.php index 63ae8d952ad6e..6054b98f96b16 100644 --- a/src/Symfony/Component/Routing/Tests/RouteTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteTest.php @@ -299,7 +299,7 @@ public function testSerializeWhenCompiledWithClass() */ public function testSerializedRepresentationKeepsWorking() { - $serialized = 'C:31:"Symfony\Component\Routing\Route":936:{a:8:{s:4:"path";s:13:"/prefix/{foo}";s:4:"host";s:20:"{locale}.example.net";s:8:"defaults";a:1:{s:3:"foo";s:7:"default";}s:12:"requirements";a:1:{s:3:"foo";s:3:"\d+";}s:7:"options";a:1:{s:14:"compiler_class";s:39:"Symfony\Component\Routing\RouteCompiler";}s:7:"schemes";a:0:{}s:7:"methods";a:0:{}s:8:"compiled";C:39:"Symfony\Component\Routing\CompiledRoute":571:{a:8:{s:4:"vars";a:2:{i:0;s:6:"locale";i:1;s:3:"foo";}s:11:"path_prefix";s:7:"/prefix";s:10:"path_regex";s:31:"{^/prefix(?:/(?P\d+))?$}sD";s:11:"path_tokens";a:2:{i:0;a:4:{i:0;s:8:"variable";i:1;s:1:"/";i:2;s:3:"\d+";i:3;s:3:"foo";}i:1;a:2:{i:0;s:4:"text";i:1;s:7:"/prefix";}}s:9:"path_vars";a:1:{i:0;s:3:"foo";}s:10:"host_regex";s:40:"{^(?P[^\.]++)\.example\.net$}sDi";s:11:"host_tokens";a:2:{i:0;a:2:{i:0;s:4:"text";i:1;s:12:".example.net";}i:1;a:4:{i:0;s:8:"variable";i:1;s:0:"";i:2;s:7:"[^\.]++";i:3;s:6:"locale";}}s:9:"host_vars";a:1:{i:0;s:6:"locale";}}}}}'; + $serialized = 'O:31:"Symfony\Component\Routing\Route":9:{s:4:"path";s:13:"/prefix/{foo}";s:4:"host";s:20:"{locale}.example.net";s:8:"defaults";a:1:{s:3:"foo";s:7:"default";}s:12:"requirements";a:1:{s:3:"foo";s:3:"\d+";}s:7:"options";a:1:{s:14:"compiler_class";s:39:"Symfony\Component\Routing\RouteCompiler";}s:7:"schemes";a:0:{}s:7:"methods";a:0:{}s:9:"condition";s:0:"";s:8:"compiled";O:39:"Symfony\Component\Routing\CompiledRoute":8:{s:4:"vars";a:2:{i:0;s:6:"locale";i:1;s:3:"foo";}s:11:"path_prefix";s:7:"/prefix";s:10:"path_regex";s:31:"{^/prefix(?:/(?P\d+))?$}sD";s:11:"path_tokens";a:2:{i:0;a:4:{i:0;s:8:"variable";i:1;s:1:"/";i:2;s:3:"\d+";i:3;s:3:"foo";}i:1;a:2:{i:0;s:4:"text";i:1;s:7:"/prefix";}}s:9:"path_vars";a:1:{i:0;s:3:"foo";}s:10:"host_regex";s:40:"{^(?P[^\.]++)\.example\.net$}sDi";s:11:"host_tokens";a:2:{i:0;a:2:{i:0;s:4:"text";i:1;s:12:".example.net";}i:1;a:4:{i:0;s:8:"variable";i:1;s:0:"";i:2;s:7:"[^\.]++";i:3;s:6:"locale";}}s:9:"host_vars";a:1:{i:0;s:6:"locale";}}}'; $unserialized = unserialize($serialized); $route = new Route('/prefix/{foo}', ['foo' => 'default'], ['foo' => '\d+']); diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php index a68a27d407219..709591e223064 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php @@ -21,7 +21,7 @@ * @author Fabien Potencier * @author Johannes M. Schmitt */ -abstract class AbstractToken implements TokenInterface +abstract class AbstractToken implements TokenInterface, \Serializable { private $user; private $roleNames = []; @@ -264,7 +264,7 @@ public function __toString() */ final public function serialize(): string { - return serialize($this->__serialize()); + throw new \BadMethodCallException('Cannot serialize '.__CLASS__); } /** diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/NullToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/NullToken.php index 28c77d7573684..eb0e74dfc4350 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/NullToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/NullToken.php @@ -100,25 +100,4 @@ public function __serialize(): array public function __unserialize(array $data): void { } - - /** - * @return string - * - * @internal in 5.3 - * @final in 5.3 - */ - public function serialize() - { - return ''; - } - - /** - * @return void - * - * @internal in 5.3 - * @final in 5.3 - */ - public function unserialize($serialized) - { - } } diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php b/src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php index 047f571ae4a20..743bb4f1182c5 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php @@ -21,7 +21,7 @@ * @author Fabien Potencier * @author Johannes M. Schmitt */ -interface TokenInterface extends \Serializable +interface TokenInterface { /** * Returns a string representation of the Token. diff --git a/src/Symfony/Component/Security/Core/CHANGELOG.md b/src/Symfony/Component/Security/Core/CHANGELOG.md index 22652b086195b..c60960c6b34f3 100644 --- a/src/Symfony/Component/Security/Core/CHANGELOG.md +++ b/src/Symfony/Component/Security/Core/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +6.0 +--- + + * `TokenInterface` does not extend `Serializable` anymore + 5.3 --- diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php index dcf479c84e710..cf80f459ed945 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php @@ -232,7 +232,7 @@ public function __toString(): string } } -class SerializableUser implements UserInterface, \Serializable +class SerializableUser implements UserInterface { private $roles; private $name; @@ -275,16 +275,6 @@ public function getSalt() { return null; } - - public function serialize(): string - { - return serialize($this->name); - } - - public function unserialize($serialized): void - { - $this->name = unserialize($serialized); - } } class ConcreteToken extends AbstractToken diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/Token/Fixtures/switch-user-token-4.4.txt b/src/Symfony/Component/Security/Core/Tests/Authentication/Token/Fixtures/switch-user-token-4.4.txt index fc8af1432871f11d7804a00d6f09fe38f8a6e582..5103e3db29fd979a4bf8a9c9b36d179d6499a943 100644 GIT binary patch delta 45 zcmZ3^HI0kWe!Uzm>VkWJ6}9iE5$~r-@Jg!1QPH21ZN9&99hjm;f+Y B4q^ZR delta 58 zcmbQnwVaF5c_O2?u%VH$nN@Y7m626-rj>!Uvz58YWJPABiIqC6re@|=)sycr{oA~d O(UNiVO(t6=###W{I1x1f diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/Token/SwitchUserTokenTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/Token/SwitchUserTokenTest.php index e605615bc9a19..90b80adc845b4 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/Token/SwitchUserTokenTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/Token/SwitchUserTokenTest.php @@ -94,7 +94,7 @@ public function testSerializeNullImpersonateUrl() /** * Tests if an old version of SwitchUserToken can still be unserialized. * - * The fixture was generated by running the following code with Symfony 4.4 and PHP 7.2. + * The fixture was generated by running the following code with Symfony 4.4 and PHP 8.0. * * serialize( * new SwitchUserToken( diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php b/src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php index 34b208b2bea0c..e36fdad32d018 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php @@ -15,7 +15,7 @@ * This class is a hand written simplified version of PHP native `ArrayObject` * class, to show that it behaves differently than the PHP native implementation. */ -class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable +class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable { private $array; @@ -63,18 +63,8 @@ public function __serialize(): array return $this->array; } - public function serialize(): string - { - return serialize($this->__serialize()); - } - public function __unserialize(array $data): void { $this->array = $data; } - - public function unserialize($serialized) - { - $this->__unserialize((array) unserialize((string) $serialized)); - } }