vendor/friendsofsymfony/oauth-server-bundle/Entity/TokenManager.php line 42

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the FOSOAuthServerBundle package.
  5.  *
  6.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace FOS\OAuthServerBundle\Entity;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Doctrine\ORM\EntityRepository;
  14. use FOS\OAuthServerBundle\Model\TokenInterface;
  15. use FOS\OAuthServerBundle\Model\TokenManager as BaseTokenManager;
  16. class TokenManager extends BaseTokenManager
  17. {
  18.     /**
  19.      * @var EntityManagerInterface
  20.      */
  21.     protected $em;
  22.     /**
  23.      * @var EntityRepository
  24.      */
  25.     protected $repository;
  26.     /**
  27.      * @var string
  28.      */
  29.     protected $class;
  30.     public function __construct(EntityManagerInterface $em$class)
  31.     {
  32.         // NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected
  33.         /** @var EntityRepository $repository */
  34.         $repository $em->getRepository($class);
  35.         $this->em $em;
  36.         $this->repository $repository;
  37.         $this->class $class;
  38.     }
  39.     /**
  40.      * {@inheritdoc}
  41.      */
  42.     public function getClass()
  43.     {
  44.         return $this->class;
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      */
  49.     public function findTokenBy(array $criteria)
  50.     {
  51.         return $this->repository->findOneBy($criteria);
  52.     }
  53.     /**
  54.      * {@inheritdoc}
  55.      */
  56.     public function updateToken(TokenInterface $token)
  57.     {
  58.         $this->em->persist($token);
  59.         $this->em->flush();
  60.     }
  61.     /**
  62.      * {@inheritdoc}
  63.      */
  64.     public function deleteToken(TokenInterface $token)
  65.     {
  66.         $this->em->remove($token);
  67.         $this->em->flush();
  68.     }
  69.     /**
  70.      * {@inheritdoc}
  71.      */
  72.     public function deleteExpired()
  73.     {
  74.         $qb $this->repository->createQueryBuilder('t');
  75.         $qb
  76.             ->delete()
  77.             ->where('t.expiresAt < ?1')
  78.             ->setParameters([=> time()])
  79.         ;
  80.         return $qb->getQuery()->execute();
  81.     }
  82. }