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

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\Common\Persistence\ObjectManager;
  12. use Doctrine\Common\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 PasswordUpdaterInterface $passwordUpdater
  31.      * @param CanonicalFieldsUpdater   $canonicalFieldsUpdater
  32.      * @param ObjectManager            $om
  33.      * @param string                   $class
  34.      */
  35.     public function __construct(PasswordUpdaterInterface $passwordUpdaterCanonicalFieldsUpdater $canonicalFieldsUpdaterObjectManager $om$class)
  36.     {
  37.         parent::__construct($passwordUpdater$canonicalFieldsUpdater);
  38.         $this->objectManager $om;
  39.         $this->class $class;
  40.     }
  41.     /**
  42.      * {@inheritdoc}
  43.      */
  44.     public function deleteUser(UserInterface $user)
  45.     {
  46.         $this->objectManager->remove($user);
  47.         $this->objectManager->flush();
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function getClass()
  53.     {
  54.         if (false !== strpos($this->class':')) {
  55.             $metadata $this->objectManager->getClassMetadata($this->class);
  56.             $this->class $metadata->getName();
  57.         }
  58.         return $this->class;
  59.     }
  60.     /**
  61.      * {@inheritdoc}
  62.      */
  63.     public function findUserBy(array $criteria)
  64.     {
  65.         return $this->getRepository()->findOneBy($criteria);
  66.     }
  67.     /**
  68.      * {@inheritdoc}
  69.      */
  70.     public function findUsers()
  71.     {
  72.         return $this->getRepository()->findAll();
  73.     }
  74.     /**
  75.      * {@inheritdoc}
  76.      */
  77.     public function reloadUser(UserInterface $user)
  78.     {
  79.         $this->objectManager->refresh($user);
  80.     }
  81.     /**
  82.      * {@inheritdoc}
  83.      */
  84.     public function updateUser(UserInterface $user$andFlush true)
  85.     {
  86.         $this->updateCanonicalFields($user);
  87.         $this->updatePassword($user);
  88.         $this->objectManager->persist($user);
  89.         if ($andFlush) {
  90.             $this->objectManager->flush();
  91.         }
  92.     }
  93.     /**
  94.      * @return ObjectRepository
  95.      */
  96.     protected function getRepository()
  97.     {
  98.         return $this->objectManager->getRepository($this->getClass());
  99.     }
  100. }