vendor/gesdinet/jwt-refresh-token-bundle/Doctrine/RefreshTokenManager.php line 42

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the GesdinetJWTRefreshTokenBundle package.
  4.  *
  5.  * (c) Gesdinet <http://www.gesdinet.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 Gesdinet\JWTRefreshTokenBundle\Doctrine;
  11. use Doctrine\Common\Persistence\ObjectManager;
  12. use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshTokenRepository;
  13. use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManager as BaseRefreshTokenManager;
  14. use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
  15. class RefreshTokenManager extends BaseRefreshTokenManager
  16. {
  17.     /**
  18.      * @var ObjectManager
  19.      */
  20.     protected $objectManager;
  21.     /**
  22.      * @var string
  23.      */
  24.     protected $class;
  25.     /**
  26.      * @var RefreshTokenRepository
  27.      */
  28.     protected $repository;
  29.     /**
  30.      * Constructor.
  31.      *
  32.      * @param ObjectManager $om
  33.      * @param string        $class
  34.      */
  35.     public function __construct(ObjectManager $om$class)
  36.     {
  37.         $this->objectManager $om;
  38.         $this->repository $om->getRepository($class);
  39.         $metadata $om->getClassMetadata($class);
  40.         $this->class $metadata->getName();
  41.     }
  42.     /**
  43.      * @param string $refreshToken
  44.      *
  45.      * @return RefreshTokenInterface
  46.      */
  47.     public function get($refreshToken)
  48.     {
  49.         return $this->repository->findOneBy(array('refreshToken' => $refreshToken));
  50.     }
  51.     /**
  52.      * @param string $username
  53.      *
  54.      * @return RefreshTokenInterface
  55.      */
  56.     public function getLastFromUsername($username)
  57.     {
  58.         return $this->repository->findOneBy(array('username' => $username), array('valid' => 'DESC'));
  59.     }
  60.     /**
  61.      * @param RefreshTokenInterface $refreshToken
  62.      * @param bool|true             $andFlush
  63.      */
  64.     public function save(RefreshTokenInterface $refreshToken$andFlush true)
  65.     {
  66.         $this->objectManager->persist($refreshToken);
  67.         if ($andFlush) {
  68.             $this->objectManager->flush();
  69.         }
  70.     }
  71.     /**
  72.      * @param RefreshTokenInterface $refreshToken
  73.      * @param bool                  $andFlush
  74.      */
  75.     public function delete(RefreshTokenInterface $refreshToken$andFlush true)
  76.     {
  77.         $this->objectManager->remove($refreshToken);
  78.         if ($andFlush) {
  79.             $this->objectManager->flush();
  80.         }
  81.     }
  82.     /**
  83.      * @param \DateTime $datetime
  84.      * @param bool      $andFlush
  85.      *
  86.      * @return RefreshTokenInterface[]
  87.      */
  88.     public function revokeAllInvalid($datetime null$andFlush true)
  89.     {
  90.         $invalidTokens $this->repository->findInvalid($datetime);
  91.         foreach ($invalidTokens as $invalidToken) {
  92.             $this->objectManager->remove($invalidToken);
  93.         }
  94.         if ($andFlush) {
  95.             $this->objectManager->flush();
  96.         }
  97.         return $invalidTokens;
  98.     }
  99.     /**
  100.      * Returns the RefreshToken fully qualified class name.
  101.      *
  102.      * @return string
  103.      */
  104.     public function getClass()
  105.     {
  106.         return $this->class;
  107.     }
  108. }