vendor/friendsofsymfony/user-bundle/Doctrine/UserManager.php line 95

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSUserBundle package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace FOS\UserBundle\Doctrine;
  11. use Doctrine\Persistence\ObjectManager;
  12. use Doctrine\Persistence\ObjectRepository;
  13. use FOS\UserBundle\Model\UserInterface;
  14. use FOS\UserBundle\Model\UserManager as BaseUserManager;
  15. use FOS\UserBundle\Util\CanonicalFieldsUpdater;
  16. use FOS\UserBundle\Util\PasswordUpdaterInterface;
  17. class UserManager extends BaseUserManager
  18. {
  19.     /**
  20.      * @var ObjectManager
  21.      */
  22.     protected $objectManager;
  23.     /**
  24.      * @var string
  25.      */
  26.     private $class;
  27.     /**
  28.      * Constructor.
  29.      *
  30.      * @param string $class
  31.      */
  32.     public function __construct(PasswordUpdaterInterface $passwordUpdaterCanonicalFieldsUpdater $canonicalFieldsUpdaterObjectManager $om$class)
  33.     {
  34.         parent::__construct($passwordUpdater$canonicalFieldsUpdater);
  35.         $this->objectManager $om;
  36.         $this->class $class;
  37.     }
  38.     /**
  39.      * {@inheritdoc}
  40.      */
  41.     public function deleteUser(UserInterface $user)
  42.     {
  43.         $this->objectManager->remove($user);
  44.         $this->objectManager->flush();
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      */
  49.     public function getClass()
  50.     {
  51.         if (false !== strpos($this->class':')) {
  52.             $metadata $this->objectManager->getClassMetadata($this->class);
  53.             $this->class $metadata->getName();
  54.         }
  55.         return $this->class;
  56.     }
  57.     /**
  58.      * {@inheritdoc}
  59.      */
  60.     public function findUserBy(array $criteria)
  61.     {
  62.         return $this->getRepository()->findOneBy($criteria);
  63.     }
  64.     /**
  65.      * {@inheritdoc}
  66.      */
  67.     public function findUsers()
  68.     {
  69.         return $this->getRepository()->findAll();
  70.     }
  71.     /**
  72.      * {@inheritdoc}
  73.      */
  74.     public function reloadUser(UserInterface $user)
  75.     {
  76.         $this->objectManager->refresh($user);
  77.     }
  78.     /**
  79.      * {@inheritdoc}
  80.      */
  81.     public function updateUser(UserInterface $user$andFlush true)
  82.     {
  83.         $this->updateCanonicalFields($user);
  84.         $this->updatePassword($user);
  85.         $this->objectManager->persist($user);
  86.         if ($andFlush) {
  87.             $this->objectManager->flush();
  88.         }
  89.     }
  90.     /**
  91.      * @return ObjectRepository
  92.      */
  93.     protected function getRepository()
  94.     {
  95.         return $this->objectManager->getRepository($this->getClass());
  96.     }
  97. }