for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2016 Spomky-Labs
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace SpomkyLabs\TestRoleHierarchyBundle\Util;
use SpomkyLabs\TestRoleHierarchyBundle\Entity\User;
use SpomkyLabs\TestRoleHierarchyBundle\Entity\UserManager;
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;
class UserProvider implements UserProviderInterface
{
private $user_manager;
public function __construct(UserManager $user_manager)
$this->user_manager = $user_manager;
}
public function loadUserByUsername($username)
$user = $this->user_manager->getUser($username);
if ($user) {
return $user;
throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
public function refreshUser(UserInterface $user)
if (!$user instanceof User) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
return $this->loadUserByUsername($user->getUsername());
public function supportsClass($class)
return $class === 'SpomkyLabs\TestRoleHierarchyBundle\Entity\User';