Last active
February 3, 2016 13:57
-
-
Save jenkoian/e66744a3af7125e5670f to your computer and use it in GitHub Desktop.
Legacy escape route LegacyUserProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Framework\Security; | |
use Acme\Authentication\User; | |
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; | |
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; | |
use Symfony\Component\Security\Core\User\UserInterface; | |
use Symfony\Component\Security\Core\User\UserProviderInterface; | |
final class LegacyUserProvider implements UserProviderInterface | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function loadUserByUsername($username) | |
{ | |
if (empty($username)) { | |
throw new UsernameNotFoundException('The username is not provided.'); | |
} | |
return new User($username); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function refreshUser(UserInterface $user) | |
{ | |
if (!$this->supportsClass(get_class($user))) { | |
throw new UnsupportedUserException(sprintf('Unsupported user class "%s"', get_class($user))); | |
} | |
return $this->loadUserByUsername($user->getUsername()); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function supportsClass($class) | |
{ | |
return $class === 'Acme\\Authentication\\User'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment