
Untitled
By: a guest on
Jul 4th, 2012 | syntax:
None | size: 1.14 KB | hits: 11 | expires: Never
<?php
namespace Knowhow\UserBundle\Services;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Knowhow\UserBundle\Entity\User;
class UserProvider implements UserProviderInterface
{
private $_user;
private $_container;
public function __construct($container)
{
$this->_user = null;
$this->_container = $container;
}
public function loadUserByUsername($username)
{
$this->_user = $this->_container->get('user_entity');
$this->_user->findByUsername($username);
if (!$this->_user->isHydrated()) {
throw new UsernameNotFoundException('Username not found!');
}
return $this->_user;
}
public function loadUser(UserInterface $user)
{
if (empty($this->_user)) {
$this->_user = new User();
}
return $this->_user;
}
public function supportsClass($class)
{
return $class == 'Knowhow\UserBundle\Entity\User';
}
}