From c7de716025d7fb5fd62cefabe521bea80fbd6c0e Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sun, 15 Jul 2012 15:47:54 +0200 Subject: [PATCH] [Security] Implemented the Serializable interface in the Role class --- src/Symfony/Component/Security/CHANGELOG.md | 1 + .../Component/Security/Core/Role/Role.php | 18 +++++++++++++++++- .../Security/Core/Role/SwitchUserRole.php | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/CHANGELOG.md b/src/Symfony/Component/Security/CHANGELOG.md index 0093677c85c32..4175749bf3e06 100644 --- a/src/Symfony/Component/Security/CHANGELOG.md +++ b/src/Symfony/Component/Security/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 2.1.0 ----- + * Added the Serializable interface on the Role class * [BC BREAK] The signature of ExceptionListener has changed * changed the HttpUtils constructor signature to take a UrlGenerator and a UrlMatcher instead of a Router * EncoderFactoryInterface::getEncoder() can now also take a class name as an argument diff --git a/src/Symfony/Component/Security/Core/Role/Role.php b/src/Symfony/Component/Security/Core/Role/Role.php index 5b50981fe1a78..7f16302b64d75 100644 --- a/src/Symfony/Component/Security/Core/Role/Role.php +++ b/src/Symfony/Component/Security/Core/Role/Role.php @@ -17,7 +17,7 @@ * * @author Fabien Potencier */ -class Role implements RoleInterface +class Role implements RoleInterface, \Serializable { private $role; @@ -38,4 +38,20 @@ public function getRole() { return $this->role; } + + /** + * {@inheritdoc} + */ + public function serialize() + { + return serialize($this->role); + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) + { + $this->role = unserialize($serialized); + } } diff --git a/src/Symfony/Component/Security/Core/Role/SwitchUserRole.php b/src/Symfony/Component/Security/Core/Role/SwitchUserRole.php index c6795841beaba..3076f34e51810 100644 --- a/src/Symfony/Component/Security/Core/Role/SwitchUserRole.php +++ b/src/Symfony/Component/Security/Core/Role/SwitchUserRole.php @@ -45,4 +45,22 @@ public function getSource() { return $this->source; } + + /** + * {@inheritdoc} + */ + public function serialize() + { + return serialize(array(parent::serialize(), $this->source)); + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) + { + list($parent, $this->source) = unserialize($serialized); + + parent::unserialize($parent); + } }