diff --git a/UPGRADE-4.3.md b/UPGRADE-4.3.md index 020f3a40181cb..2ca3698ac978c 100644 --- a/UPGRADE-4.3.md +++ b/UPGRADE-4.3.md @@ -115,7 +115,7 @@ Security * The `Firewall::handleRequest()` method is deprecated, use `Firewall::callListeners()` instead. * The `AbstractToken::serialize()`, `AbstractToken::unserialize()`, `AuthenticationException::serialize()` and `AuthenticationException::unserialize()` - methods are now final, use `getState()` and `setState()` instead. + methods are now final, use `__serialize()` and `__unserialize()` instead. Before: ```php @@ -133,15 +133,15 @@ Security After: ```php - protected function getState(): array + public function __serialize(): array { - return [$this->myLocalVar, parent::getState()]; + return [$this->myLocalVar, parent::__serialize()]; } - protected function setState(array $data) + public function __unserialize(array $data): void { [$this->myLocalVar, $parentData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } ``` diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 68001974bb92c..c82a3c7abc0e8 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -293,7 +293,7 @@ Security * The `Firewall::handleRequest()` method has been removed, use `Firewall::callListeners()` instead. * `\Serializable` interface has been removed from `AbstractToken` and `AuthenticationException`, thus `serialize()` and `unserialize()` aren't available. - Use `getState()` and `setState()` instead. + Use `__serialize()` and `__unserialize()` instead. Before: ```php @@ -311,15 +311,15 @@ Security After: ```php - protected function getState(): array + public function __serialize(): array { - return [$this->myLocalVar, parent::getState()]; + return [$this->myLocalVar, parent::__serialize()]; } - protected function setState(array $data) + public function __unserialize(array $data): void { [$this->myLocalVar, $parentData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } ``` diff --git a/src/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php b/src/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php index 006724014a2a1..47fa14090e26d 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php +++ b/src/Symfony/Component/Form/Tests/Fixtures/CustomArrayObject.php @@ -58,13 +58,23 @@ public function count() return \count($this->array); } + public function __serialize(): array + { + return $this->array; + } + public function serialize() { - return serialize($this->array); + return serialize($this->__serialize()); + } + + public function __unserialize(array $data): void + { + $this->array = $data; } public function unserialize($serialized) { - $this->array = (array) unserialize((string) $serialized); + $this->__unserialize((array) unserialize((string) $serialized)); } } diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php index 4b18e725ae9e4..cb659f907c15b 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/NonTraversableArrayObject.php @@ -53,13 +53,23 @@ public function count() return \count($this->array); } + public function __serialize(): array + { + return $this->array; + } + public function serialize() { - return serialize($this->array); + return serialize($this->__serialize()); + } + + public function __unserialize(array $data): void + { + $this->array = $data; } public function unserialize($serialized) { - $this->array = (array) unserialize((string) $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 b075286f4a70e..ba5ec36e76bd2 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TraversableArrayObject.php +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TraversableArrayObject.php @@ -58,13 +58,23 @@ public function count() return \count($this->array); } + public function __serialize(): array + { + return $this->array; + } + public function serialize() { - return serialize($this->array); + return serialize($this->__serialize()); + } + + public function __unserialize(array $data): void + { + $this->array = $data; } public function unserialize($serialized) { - $this->array = (array) unserialize((string) $serialized); + $this->__unserialize((array) unserialize((string) $serialized)); } } diff --git a/src/Symfony/Component/Routing/CompiledRoute.php b/src/Symfony/Component/Routing/CompiledRoute.php index b8919c56cc444..06dc87d74015c 100644 --- a/src/Symfony/Component/Routing/CompiledRoute.php +++ b/src/Symfony/Component/Routing/CompiledRoute.php @@ -49,12 +49,9 @@ public function __construct(string $staticPrefix, string $regex, array $tokens, $this->variables = $variables; } - /** - * @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore - */ - public function serialize() + public function __serialize(): array { - return serialize([ + return [ 'vars' => $this->variables, 'path_prefix' => $this->staticPrefix, 'path_regex' => $this->regex, @@ -63,16 +60,19 @@ public function serialize() 'host_regex' => $this->hostRegex, 'host_tokens' => $this->hostTokens, 'host_vars' => $this->hostVariables, - ]); + ]; } /** * @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore */ - public function unserialize($serialized) + public function serialize() { - $data = unserialize($serialized, ['allowed_classes' => false]); + return serialize($this->__serialize()); + } + public function __unserialize(array $data): void + { $this->variables = $data['vars']; $this->staticPrefix = $data['path_prefix']; $this->regex = $data['path_regex']; @@ -83,6 +83,14 @@ public function unserialize($serialized) $this->hostVariables = $data['host_vars']; } + /** + * @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore + */ + public function unserialize($serialized) + { + $this->__unserialize(unserialize($serialized, ['allowed_classes' => false])); + } + /** * Returns the static prefix. * diff --git a/src/Symfony/Component/Routing/Route.php b/src/Symfony/Component/Routing/Route.php index 8028d3801228d..178c5d3ac213b 100644 --- a/src/Symfony/Component/Routing/Route.php +++ b/src/Symfony/Component/Routing/Route.php @@ -62,12 +62,9 @@ public function __construct(string $path, array $defaults = [], array $requireme $this->setCondition($condition); } - /** - * @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore - */ - public function serialize() + public function __serialize(): array { - return serialize([ + return [ 'path' => $this->path, 'host' => $this->host, 'defaults' => $this->defaults, @@ -77,15 +74,19 @@ public function serialize() 'methods' => $this->methods, 'condition' => $this->condition, 'compiled' => $this->compiled, - ]); + ]; } /** * @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore */ - public function unserialize($serialized) + public function serialize() + { + return serialize($this->__serialize()); + } + + public function __unserialize(array $data): void { - $data = unserialize($serialized); $this->path = $data['path']; $this->host = $data['host']; $this->defaults = $data['defaults']; @@ -102,6 +103,14 @@ public function unserialize($serialized) } } + /** + * @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore + */ + public function unserialize($serialized) + { + $this->__unserialize(unserialize($serialized)); + } + /** * Returns the pattern for the path. * diff --git a/src/Symfony/Component/Security/CHANGELOG.md b/src/Symfony/Component/Security/CHANGELOG.md index fc6b60a3a1309..525972bdf4166 100644 --- a/src/Symfony/Component/Security/CHANGELOG.md +++ b/src/Symfony/Component/Security/CHANGELOG.md @@ -11,7 +11,7 @@ CHANGELOG * The `getRoles()` method of the `TokenInterface` is deprecated. Tokens must implement the `getRoleNames()` method instead and return roles as strings. * Made the `serialize()` and `unserialize()` methods of `AbstractToken` and - `AuthenticationException` final, use `getState()`/`setState()` instead + `AuthenticationException` final, use `__serialize()`/`__unserialize()` instead * `AuthenticationException` doesn't implement `Serializable` anymore * Deprecated the `ListenerInterface`, turn your listeners into callables instead * Deprecated `Firewall::handleRequest()`, use `Firewall::callListeners()` instead diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php index b409e4b5635fd..f8f05a1ed80ec 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php @@ -142,16 +142,36 @@ public function eraseCredentials() } } + /** + * Returns all the necessary state of the object for serialization purposes. + * + * There is no need to serialize any entry, they should be returned as-is. + * If you extend this method, keep in mind you MUST guarantee parent data is present in the state. + * Here is an example of how to extend this method: + * + * public function __serialize(): array + * { + * return [$this->childAttribute, parent::__serialize()]; + * } + * + * + * @see __unserialize() + */ + public function __serialize(): array + { + return [$this->user, $this->authenticated, $this->roles, $this->attributes, $this->roleNames]; + } + /** * {@inheritdoc} * - * @final since Symfony 4.3, use getState() instead + * @final since Symfony 4.3, use __serialize() instead * - * @internal since Symfony 4.3, use getState() instead + * @internal since Symfony 4.3, use __serialize() instead */ public function serialize() { - $serialized = $this->getState(); + $serialized = $this->__serialize(); if (null === $isCalledFromOverridingMethod = \func_num_args() ? \func_get_arg(0) : null) { $trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2); @@ -162,56 +182,36 @@ public function serialize() } /** - * {@inheritdoc} - * - * @final since Symfony 4.3, use setState() instead - * - * @internal since Symfony 4.3, use setState() instead - */ - public function unserialize($serialized) - { - $this->setState(\is_array($serialized) ? $serialized : unserialize($serialized)); - } - - /** - * Returns all the necessary state of the object for serialization purposes. + * Restores the object state from an array given by __serialize(). * - * There is no need to serialize any entry, they should be returned as-is. - * If you extend this method, keep in mind you MUST guarantee parent data is present in the state. + * There is no need to unserialize any entry in $data, they are already ready-to-use. + * If you extend this method, keep in mind you MUST pass the parent data to its respective class. * Here is an example of how to extend this method: * - * protected function getState(): array + * public function __unserialize(array $data): void * { - * return [$this->childAttribute, parent::getState()]; + * [$this->childAttribute, $parentData] = $data; + * parent::__unserialize($parentData); * } * * - * @see setState() + * @see __serialize() */ - protected function getState(): array + public function __unserialize(array $data): void { - return [$this->user, $this->authenticated, $this->roles, $this->attributes, $this->roleNames]; + [$this->user, $this->authenticated, $this->roles, $this->attributes, $this->roleNames] = $data; } /** - * Restores the object state from an array given by getState(). + * {@inheritdoc} * - * There is no need to unserialize any entry in $data, they are already ready-to-use. - * If you extend this method, keep in mind you MUST pass the parent data to its respective class. - * Here is an example of how to extend this method: - * - * protected function setState(array $data) - * { - * [$this->childAttribute, $parentData] = $data; - * parent::setState($parentData); - * } - * + * @final since Symfony 4.3, use __unserialize() instead * - * @see getState() + * @internal since Symfony 4.3, use __unserialize() instead */ - protected function setState(array $data) + public function unserialize($serialized) { - [$this->user, $this->authenticated, $this->roles, $this->attributes, $this->roleNames] = $data; + $this->__unserialize(\is_array($serialized) ? $serialized : unserialize($serialized)); } /** diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/AnonymousToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/AnonymousToken.php index c233c2bd16dc3..b94e8cbb2b953 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/AnonymousToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/AnonymousToken.php @@ -55,17 +55,17 @@ public function getSecret() /** * {@inheritdoc} */ - protected function getState(): array + public function __serialize(): array { - return [$this->secret, parent::getState()]; + return [$this->secret, parent::__serialize()]; } /** * {@inheritdoc} */ - protected function setState(array $data) + public function __unserialize(array $data): void { [$this->secret, $parentData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php index eb407e50c9c66..3532a8adbac19 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php @@ -75,17 +75,17 @@ public function eraseCredentials() /** * {@inheritdoc} */ - protected function getState(): array + public function __serialize(): array { - return [$this->credentials, $this->providerKey, parent::getState()]; + return [$this->credentials, $this->providerKey, parent::__serialize()]; } /** * {@inheritdoc} */ - protected function setState(array $data) + public function __unserialize(array $data): void { [$this->credentials, $this->providerKey, $parentData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php index 40daa68923c05..766201ecf14e0 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php @@ -92,17 +92,17 @@ public function getCredentials() /** * {@inheritdoc} */ - protected function getState(): array + public function __serialize(): array { - return [$this->secret, $this->providerKey, parent::getState()]; + return [$this->secret, $this->providerKey, parent::__serialize()]; } /** * {@inheritdoc} */ - protected function setState(array $data) + public function __unserialize(array $data): void { [$this->secret, $this->providerKey, $parentData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/SwitchUserToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/SwitchUserToken.php index 8e73876306aa9..ec98f04cfe8b2 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/SwitchUserToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/SwitchUserToken.php @@ -44,17 +44,17 @@ public function getOriginalToken(): TokenInterface /** * {@inheritdoc} */ - protected function getState(): array + public function __serialize(): array { - return [$this->originalToken, parent::getState()]; + return [$this->originalToken, parent::__serialize()]; } /** * {@inheritdoc} */ - protected function setState(array $data) + public function __unserialize(array $data): void { [$this->originalToken, $parentData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php index 79e5780f09ce6..4c4773578373e 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php @@ -87,17 +87,17 @@ public function eraseCredentials() /** * {@inheritdoc} */ - protected function getState(): array + public function __serialize(): array { - return [$this->credentials, $this->providerKey, parent::getState()]; + return [$this->credentials, $this->providerKey, parent::__serialize()]; } /** * {@inheritdoc} */ - protected function setState(array $data) + public function __unserialize(array $data): void { [$this->credentials, $this->providerKey, $parentData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php b/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php index 4d707c07d1871..f3fa661c31f4e 100644 --- a/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php +++ b/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php @@ -42,17 +42,17 @@ public function setUser(UserInterface $user) /** * {@inheritdoc} */ - protected function getState(): array + public function __serialize(): array { - return [$this->user, parent::getState()]; + return [$this->user, parent::__serialize()]; } /** * {@inheritdoc} */ - protected function setState(array $data) + public function __unserialize(array $data): void { [$this->user, $parentData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php index 82f6db65d6099..0caa0563fd83b 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php @@ -38,16 +38,36 @@ public function setToken(TokenInterface $token) $this->token = $token; } + /** + * Returns all the necessary state of the object for serialization purposes. + * + * There is no need to serialize any entry, they should be returned as-is. + * If you extend this method, keep in mind you MUST guarantee parent data is present in the state. + * Here is an example of how to extend this method: + * + * public function __serialize(): array + * { + * return [$this->childAttribute, parent::__serialize()]; + * } + * + * + * @see __unserialize() + */ + public function __serialize(): array + { + return [$this->token, $this->code, $this->message, $this->file, $this->line]; + } + /** * {@inheritdoc} * - * @final since Symfony 4.3, use getState() instead + * @final since Symfony 4.3, use __serialize() instead * - * @internal since Symfony 4.3, use getState() instead + * @internal since Symfony 4.3, use __serialize() instead */ public function serialize() { - $serialized = $this->getState(); + $serialized = $this->__serialize(); if (null === $isCalledFromOverridingMethod = \func_num_args() ? \func_get_arg(0) : null) { $trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2); @@ -57,83 +77,69 @@ public function serialize() return $isCalledFromOverridingMethod ? $serialized : serialize($serialized); } + /** + * Restores the object state from an array given by __serialize(). + * + * There is no need to unserialize any entry in $data, they are already ready-to-use. + * If you extend this method, keep in mind you MUST pass the parent data to its respective class. + * Here is an example of how to extend this method: + * + * public function __unserialize(array $data): void + * { + * [$this->childAttribute, $parentData] = $data; + * parent::__unserialize($parentData); + * } + * + * + * @see __serialize() + */ + public function __unserialize(array $data): void + { + [$this->token, $this->code, $this->message, $this->file, $this->line] = $data; + } + /** * {@inheritdoc} * - * @final since Symfony 4.3, use setState() instead + * @final since Symfony 4.3, use __unserialize() instead * - * @internal since Symfony 4.3, use setState() instead + * @internal since Symfony 4.3, use __unserialize() instead */ public function unserialize($serialized) { - $this->setState(\is_array($serialized) ? $serialized : unserialize($serialized)); + $this->__unserialize(\is_array($serialized) ? $serialized : unserialize($serialized)); } + /** + * @internal + */ public function __sleep() { if (__CLASS__ !== $c = (new \ReflectionMethod($this, 'serialize'))->getDeclaringClass()->name) { - @trigger_error(sprintf('Implementing the "%s::serialize()" method is deprecated since Symfony 4.3, implement the getState() and setState() methods instead.', $c), E_USER_DEPRECATED); + @trigger_error(sprintf('Implementing the "%s::serialize()" method is deprecated since Symfony 4.3, implement the __serialize() and __unserialize() methods instead.', $c), E_USER_DEPRECATED); $this->serialized = $this->serialize(); } else { - $this->serialized = $this->getState(); + $this->serialized = $this->__serialize(); } return ['serialized']; } + /** + * @internal + */ public function __wakeup() { if (__CLASS__ !== $c = (new \ReflectionMethod($this, 'unserialize'))->getDeclaringClass()->name) { - @trigger_error(sprintf('Implementing the "%s::unserialize()" method is deprecated since Symfony 4.3, implement the getState() and setState() methods instead.', $c), E_USER_DEPRECATED); + @trigger_error(sprintf('Implementing the "%s::unserialize()" method is deprecated since Symfony 4.3, implement the __serialize() and __unserialize() methods instead.', $c), E_USER_DEPRECATED); $this->unserialize($this->serialized); } else { - $this->setState($this->serialized); + $this->__unserialize($this->serialized); } unset($this->serialized); } - /** - * Returns all the necessary state of the object for serialization purposes. - * - * There is no need to serialize any entry, they should be returned as-is. - * If you extend this method, keep in mind you MUST guarantee parent data is present in the state. - * Here is an example of how to extend this method: - * - * protected function getState(): array - * { - * return [$this->childAttribute, parent::getState()]; - * } - * - * - * @see setState() - */ - protected function getState(): array - { - return [$this->token, $this->code, $this->message, $this->file, $this->line]; - } - - /** - * Restores the object state from an array given by getState(). - * - * There is no need to unserialize any entry in $data, they are already ready-to-use. - * If you extend this method, keep in mind you MUST pass the parent data to its respective class. - * Here is an example of how to extend this method: - * - * protected function setState(array $data) - * { - * [$this->childAttribute, $parentData] = $data; - * parent::setState($parentData); - * } - * - * - * @see getState() - */ - protected function setState(array $data) - { - [$this->token, $this->code, $this->message, $this->file, $this->line] = $data; - } - /** * Message key to be used by the translation component. * diff --git a/src/Symfony/Component/Security/Core/Exception/CustomUserMessageAuthenticationException.php b/src/Symfony/Component/Security/Core/Exception/CustomUserMessageAuthenticationException.php index bd1b18eb328f0..b64d267b4868c 100644 --- a/src/Symfony/Component/Security/Core/Exception/CustomUserMessageAuthenticationException.php +++ b/src/Symfony/Component/Security/Core/Exception/CustomUserMessageAuthenticationException.php @@ -58,17 +58,17 @@ public function getMessageData() /** * {@inheritdoc} */ - protected function getState(): array + public function __serialize(): array { - return [parent::getState(), $this->messageKey, $this->messageData]; + return [parent::__serialize(), $this->messageKey, $this->messageData]; } /** * {@inheritdoc} */ - protected function setState(array $data) + public function __unserialize(array $data): void { [$parentData, $this->messageKey, $this->messageData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php index 155f80e357bcd..31dd486eec12d 100644 --- a/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php @@ -60,17 +60,17 @@ public function getMessageData() /** * {@inheritdoc} */ - protected function getState(): array + public function __serialize(): array { - return [$this->username, parent::getState()]; + return [$this->username, parent::__serialize()]; } /** * {@inheritdoc} */ - protected function setState(array $data) + public function __unserialize(array $data): void { [$this->username, $parentData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationTrustResolverTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationTrustResolverTest.php index f55f161476f58..940dcaffaa958 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationTrustResolverTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationTrustResolverTest.php @@ -148,10 +148,18 @@ protected function getResolver() class FakeCustomToken implements TokenInterface { + public function __serialize(): array + { + } + public function serialize() { } + public function __unserialize(array $data): void + { + } + public function unserialize($serialized) { } 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 188eeb5ab7def..fde5c139a5a69 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php @@ -278,15 +278,15 @@ public function __construct(array $roles = [], UserInterface $user = null) } } - protected function getState(): array + public function __serialize(): array { - return [$this->credentials, parent::getState()]; + return [$this->credentials, parent::__serialize()]; } - protected function setState(array $data) + public function __unserialize(array $data): void { [$this->credentials, $parentState] = $data; - parent::setState($parentState); + parent::__unserialize($parentState); } public function getCredentials() diff --git a/src/Symfony/Component/Security/Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php b/src/Symfony/Component/Security/Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php index 58eb04efbdce9..9726707506cbb 100644 --- a/src/Symfony/Component/Security/Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php @@ -17,16 +17,16 @@ class ChildCustomUserMessageAuthenticationException extends CustomUserMessageAuthenticationException { - protected function getState(): array + public function __serialize(): array { - return [$this->childMember, parent::getState()]; + return [$this->childMember, parent::__serialize()]; } - public function setState(array $data) + public function __unserialize(array $data): void { [$this->childMember, $parentData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Guard/Token/PostAuthenticationGuardToken.php b/src/Symfony/Component/Security/Guard/Token/PostAuthenticationGuardToken.php index bde47244a0014..245ce241074e1 100644 --- a/src/Symfony/Component/Security/Guard/Token/PostAuthenticationGuardToken.php +++ b/src/Symfony/Component/Security/Guard/Token/PostAuthenticationGuardToken.php @@ -73,17 +73,17 @@ public function getProviderKey() /** * {@inheritdoc} */ - protected function getState(): array + public function __serialize(): array { - return [$this->providerKey, parent::getState()]; + return [$this->providerKey, parent::__serialize()]; } /** * {@inheritdoc} */ - protected function setState(array $data) + public function __unserialize(array $data): void { [$this->providerKey, $parentData] = $data; - parent::setState($parentData); + parent::__unserialize($parentData); } } diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php b/src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php index 1edf1de0811db..9b5303c167c0b 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php @@ -58,13 +58,23 @@ public function count() return \count($this->array); } + public function __serialize(): array + { + return $this->array; + } + public function serialize() { - return serialize($this->array); + return serialize($this->__serialize()); + } + + public function __unserialize(array $data): void + { + $this->array = $data; } public function unserialize($serialized) { - $this->array = (array) unserialize((string) $serialized); + $this->__unserialize((array) unserialize((string) $serialized)); } }