From fa9b920051a113246893f9e9c91726c940684fa0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 16 Jun 2011 18:00:36 +0200 Subject: [PATCH] [Security] renamed UserProviderInterface::loadUser() to refreshUser() --- UPDATE.md | 4 ++++ .../Security/Core/User/ChainUserProvider.php | 4 ++-- .../Security/Core/User/EntityUserProvider.php | 2 +- .../Security/Core/User/InMemoryUserProvider.php | 2 +- .../Security/Core/User/UserProviderInterface.php | 4 ++-- .../Security/Http/Firewall/ContextListener.php | 2 +- .../Security/Core/User/ChainUserProviderTest.php | 16 ++++++++-------- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/UPDATE.md b/UPDATE.md index 418f0746ad..99f3a1249d 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -9,6 +9,10 @@ timeline closely anyway. beta4 to beta5 -------------- +* `UserProviderInterface::loadUser()` has been renamed to + `UserProviderInterface::refreshUser()` to make the goal of the method + clearer. + * The `$kernel` property on `WebTestCase` is now static. Change any instances of `$this->kernel` in your functional tests to `self::$kernel`. diff --git a/src/Symfony/Component/Security/Core/User/ChainUserProvider.php b/src/Symfony/Component/Security/Core/User/ChainUserProvider.php index d2b6e8cb54..e6aca32984 100644 --- a/src/Symfony/Component/Security/Core/User/ChainUserProvider.php +++ b/src/Symfony/Component/Security/Core/User/ChainUserProvider.php @@ -50,11 +50,11 @@ class ChainUserProvider implements UserProviderInterface /** * {@inheritDoc} */ - public function loadUser(UserInterface $user) + public function refreshUser(UserInterface $user) { foreach ($this->providers as $provider) { try { - return $provider->loadUser($user); + return $provider->refreshUser($user); } catch (UnsupportedUserException $unsupported) { // try next one } diff --git a/src/Symfony/Component/Security/Core/User/EntityUserProvider.php b/src/Symfony/Component/Security/Core/User/EntityUserProvider.php index 61dd708269..cc6f6eddb0 100644 --- a/src/Symfony/Component/Security/Core/User/EntityUserProvider.php +++ b/src/Symfony/Component/Security/Core/User/EntityUserProvider.php @@ -66,7 +66,7 @@ class EntityUserProvider implements UserProviderInterface /** * {@inheritDoc} */ - public function loadUser(UserInterface $user) + public function refreshUser(UserInterface $user) { if (!$user instanceof $this->class) { throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); diff --git a/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php b/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php index e73eb9522b..eae20833fa 100644 --- a/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php +++ b/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php @@ -78,7 +78,7 @@ class InMemoryUserProvider implements UserProviderInterface /** * {@inheritDoc} */ - public function loadUser(UserInterface $user) + public function refreshUser(UserInterface $user) { if (!$user instanceof User) { throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); diff --git a/src/Symfony/Component/Security/Core/User/UserProviderInterface.php b/src/Symfony/Component/Security/Core/User/UserProviderInterface.php index fb5c10696f..11fd62cdac 100644 --- a/src/Symfony/Component/Security/Core/User/UserProviderInterface.php +++ b/src/Symfony/Component/Security/Core/User/UserProviderInterface.php @@ -33,7 +33,7 @@ interface UserProviderInterface function loadUserByUsername($username); /** - * Loads the user for the account interface. + * Refreshes the user for the account interface. * * It is up to the implementation if it decides to reload the user data * from the database, or if it simply merges the passed User into the @@ -44,7 +44,7 @@ interface UserProviderInterface * * @return UserInterface */ - function loadUser(UserInterface $user); + function refreshUser(UserInterface $user); /** * Whether this provider supports the given user class diff --git a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php index 950429a1a5..49362666a9 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php @@ -128,7 +128,7 @@ class ContextListener implements ListenerInterface foreach ($this->userProviders as $provider) { try { - $token->setUser($provider->loadUser($user)); + $token->setUser($provider->refreshUser($user)); if (null !== $this->logger) { $this->logger->debug(sprintf('Username "%s" was reloaded from user provider.', $user->getUsername())); diff --git a/tests/Symfony/Tests/Component/Security/Core/User/ChainUserProviderTest.php b/tests/Symfony/Tests/Component/Security/Core/User/ChainUserProviderTest.php index 4d974cef07..3dc25b7af1 100644 --- a/tests/Symfony/Tests/Component/Security/Core/User/ChainUserProviderTest.php +++ b/tests/Symfony/Tests/Component/Security/Core/User/ChainUserProviderTest.php @@ -66,47 +66,47 @@ class ChainUserProviderTest extends \PHPUnit_Framework_TestCase $provider->loadUserByUsername('foo'); } - public function testloadUser() + public function testRefreshUser() { $provider1 = $this->getProvider(); $provider1 ->expects($this->once()) - ->method('loadUser') + ->method('refreshUser') ->will($this->throwException(new UnsupportedUserException('unsupported'))) ; $provider2 = $this->getProvider(); $provider2 ->expects($this->once()) - ->method('loadUser') + ->method('refreshUser') ->will($this->returnValue($account = $this->getAccount())) ; $provider = new ChainUserProvider(array($provider1, $provider2)); - $this->assertSame($account, $provider->loadUser($this->getAccount())); + $this->assertSame($account, $provider->refreshUser($this->getAccount())); } /** * @expectedException Symfony\Component\Security\Core\Exception\UnsupportedUserException */ - public function testloadUserThrowsUnsupportedUserException() + public function testRefreshUserThrowsUnsupportedUserException() { $provider1 = $this->getProvider(); $provider1 ->expects($this->once()) - ->method('loadUser') + ->method('refreshUser') ->will($this->throwException(new UnsupportedUserException('unsupported'))) ; $provider2 = $this->getProvider(); $provider2 ->expects($this->once()) - ->method('loadUser') + ->method('refreshUser') ->will($this->throwException(new UnsupportedUserException('unsupported'))) ; $provider = new ChainUserProvider(array($provider1, $provider2)); - $provider->loadUser($this->getAccount()); + $provider->refreshUser($this->getAccount()); } public function testSupportsClass()