Skip to content

Instantly share code, notes, and snippets.

@jenkoian
Last active February 3, 2016 13:57
Show Gist options
  • Save jenkoian/e66744a3af7125e5670f to your computer and use it in GitHub Desktop.
Save jenkoian/e66744a3af7125e5670f to your computer and use it in GitHub Desktop.
Legacy escape route LegacyUserProvider.php
<?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