vendor/friendsofsymfony/user-bundle/Model/UserManager.php line 40

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\Model;
  11. use FOS\UserBundle\Util\CanonicalFieldsUpdater;
  12. use FOS\UserBundle\Util\PasswordUpdaterInterface;
  13. /**
  14.  * Abstract User Manager implementation which can be used as base class for your
  15.  * concrete manager.
  16.  *
  17.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  18.  */
  19. abstract class UserManager implements UserManagerInterface
  20. {
  21.     private $passwordUpdater;
  22.     private $canonicalFieldsUpdater;
  23.     public function __construct(PasswordUpdaterInterface $passwordUpdaterCanonicalFieldsUpdater $canonicalFieldsUpdater)
  24.     {
  25.         $this->passwordUpdater $passwordUpdater;
  26.         $this->canonicalFieldsUpdater $canonicalFieldsUpdater;
  27.     }
  28.     /**
  29.      * {@inheritdoc}
  30.      */
  31.     public function createUser()
  32.     {
  33.         $class $this->getClass();
  34.         $user = new $class();
  35.         return $user;
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public function findUserByEmail($email)
  41.     {
  42.         return $this->findUserBy(array('emailCanonical' => $this->canonicalFieldsUpdater->canonicalizeEmail($email)));
  43.     }
  44.     /**
  45.      * {@inheritdoc}
  46.      */
  47.     public function findUserByUsername($username)
  48.     {
  49.         return $this->findUserBy(array('usernameCanonical' => $this->canonicalFieldsUpdater->canonicalizeUsername($username)));
  50.     }
  51.     /**
  52.      * {@inheritdoc}
  53.      */
  54.     public function findUserByUsernameOrEmail($usernameOrEmail)
  55.     {
  56.         if (preg_match('/^.+\@\S+\.\S+$/'$usernameOrEmail)) {
  57.             $user $this->findUserByEmail($usernameOrEmail);
  58.             if (null !== $user) {
  59.                 return $user;
  60.             }
  61.         }
  62.         return $this->findUserByUsername($usernameOrEmail);
  63.     }
  64.     /**
  65.      * {@inheritdoc}
  66.      */
  67.     public function findUserByConfirmationToken($token)
  68.     {
  69.         return $this->findUserBy(array('confirmationToken' => $token));
  70.     }
  71.     /**
  72.      * {@inheritdoc}
  73.      */
  74.     public function updateCanonicalFields(UserInterface $user)
  75.     {
  76.         $this->canonicalFieldsUpdater->updateCanonicalFields($user);
  77.     }
  78.     /**
  79.      * {@inheritdoc}
  80.      */
  81.     public function updatePassword(UserInterface $user)
  82.     {
  83.         $this->passwordUpdater->hashPassword($user);
  84.     }
  85.     /**
  86.      * @return PasswordUpdaterInterface
  87.      */
  88.     protected function getPasswordUpdater()
  89.     {
  90.         return $this->passwordUpdater;
  91.     }
  92.     /**
  93.      * @return CanonicalFieldsUpdater
  94.      */
  95.     protected function getCanonicalFieldsUpdater()
  96.     {
  97.         return $this->canonicalFieldsUpdater;
  98.     }
  99. }