infrastructure/OAuthBundle/Entity/TokenManager.php line 39

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. protected \Doctrine\ORM\EntityManagerInterface $em;
  19. /**
  20. * @var EntityRepository
  21. */
  22. protected $repository;
  23. /**
  24. * @var string
  25. */
  26. protected $class;
  27. public function __construct(EntityManagerInterface $em, $class)
  28. {
  29. // NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected
  30. /** @var EntityRepository $repository */
  31. $repository = $em->getRepository($class);
  32. $this->em = $em;
  33. $this->repository = $repository;
  34. $this->class = $class;
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function getClass()
  40. {
  41. return $this->class;
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function findTokenBy(array $criteria)
  47. {
  48. return $this->repository->findOneBy($criteria);
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function updateToken(TokenInterface $token)
  54. {
  55. $this->em->persist($token);
  56. $this->em->flush();
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function deleteToken(TokenInterface $token)
  62. {
  63. $this->em->remove($token);
  64. $this->em->flush();
  65. }
  66. /**
  67. * {@inheritdoc}
  68. */
  69. public function deleteExpired()
  70. {
  71. $qb = $this->repository->createQueryBuilder('t');
  72. $qb
  73. ->delete()
  74. ->where('t.expiresAt < ?1')
  75. ->setParameters([1 => time()])
  76. ;
  77. return $qb->getQuery()->execute();
  78. }
  79. }