Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 1.14 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. namespace Knowhow\UserBundle\Services;
  4.  
  5. use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
  6. use Symfony\Component\Security\Core\User\UserProviderInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Knowhow\UserBundle\Entity\User;
  9.  
  10. class UserProvider implements UserProviderInterface
  11. {
  12.  
  13.     private $_user;
  14.     private $_container;
  15.  
  16.     public function __construct($container)
  17.     {
  18.         $this->_user = null;
  19.         $this->_container = $container;
  20.     }
  21.  
  22.     public function loadUserByUsername($username)
  23.     {
  24.         $this->_user = $this->_container->get('user_entity');
  25.         $this->_user->findByUsername($username);
  26.  
  27.         if (!$this->_user->isHydrated()) {
  28.             throw new UsernameNotFoundException('Username not found!');
  29.         }
  30.  
  31.         return $this->_user;
  32.     }
  33.  
  34.     public function loadUser(UserInterface $user)
  35.     {
  36.         if (empty($this->_user)) {
  37.             $this->_user = new User();
  38.         }
  39.         return $this->_user;
  40.     }
  41.  
  42.     public function supportsClass($class)
  43.     {
  44.         return $class == 'Knowhow\UserBundle\Entity\User';
  45.     }
  46.  
  47. }