diff options
author | Fabien Potencier <fabien.potencier@gmail.com> | 2012-07-15 14:10:42 +0200 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2012-07-15 14:10:42 +0200 |
commit | b7823dc1c0f06e647303b8a15a78316259134b5f (patch) | |
tree | 0554680923d3a69df2e517abd40d3090c5873864 | |
parent | cf02a21415f346cd8eb5a33c60266b51c3e90623 (diff) | |
parent | 671647a3a9fe3d13637f5db0f2bc411b9be0de2a (diff) | |
download | symfony-security-b7823dc1c0f06e647303b8a15a78316259134b5f.zip symfony-security-b7823dc1c0f06e647303b8a15a78316259134b5f.tar.gz symfony-security-b7823dc1c0f06e647303b8a15a78316259134b5f.tar.bz2 |
merged branch stof/serializable_role (PR #4925)
Commits
-------
1f2f866 fixed the serialization of the SwitchUserRole
b55930a [Security] Implemented the Serializable interface in the Role class
Discussion
----------
[Security] Implemented the Serializable interface in the Role class
The Role class is serialized in the session for each role of the user. Implementing the Serializable interface allows to reduce the size of the data.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | Core/Role/Role.php | 18 | ||||
-rw-r--r-- | Core/Role/SwitchUserRole.php | 18 |
3 files changed, 36 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 0093677..4175749 100644 --- a/CHANGELOG.md +++ b/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/Core/Role/Role.php b/Core/Role/Role.php index 5b50981..7f16302 100644 --- a/Core/Role/Role.php +++ b/Core/Role/Role.php @@ -17,7 +17,7 @@ namespace Symfony\Component\Security\Core\Role; * * @author Fabien Potencier <fabien@symfony.com> */ -class Role implements RoleInterface +class Role implements RoleInterface, \Serializable { private $role; @@ -38,4 +38,20 @@ class Role implements RoleInterface { return $this->role; } + + /** + * {@inheritdoc} + */ + public function serialize() + { + return serialize($this->role); + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) + { + $this->role = unserialize($serialized); + } } diff --git a/Core/Role/SwitchUserRole.php b/Core/Role/SwitchUserRole.php index c679584..3076f34 100644 --- a/Core/Role/SwitchUserRole.php +++ b/Core/Role/SwitchUserRole.php @@ -45,4 +45,22 @@ class SwitchUserRole extends Role { 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); + } } |