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.
This commit is contained in:
Fabien Potencier 2012-07-15 14:10:42 +02:00
commit b0750f6dcd
3 changed files with 36 additions and 1 deletions

View File

@ -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

View File

@ -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);
}
}

View File

@ -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);
}
}