vendor/league/oauth2-server-bundle/src/Manager/Doctrine/AccessTokenManager.php line 34

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace League\Bundle\OAuth2ServerBundle\Manager\Doctrine;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use League\Bundle\OAuth2ServerBundle\Manager\AccessTokenManagerInterface;
  6. use League\Bundle\OAuth2ServerBundle\Model\AccessToken;
  7. use League\Bundle\OAuth2ServerBundle\Model\AccessTokenInterface;
  8. final class AccessTokenManager implements AccessTokenManagerInterface
  9. {
  10.     /**
  11.      * @var EntityManagerInterface
  12.      */
  13.     private $entityManager;
  14.     /** @var bool */
  15.     private $persistAccessToken;
  16.     public function __construct(EntityManagerInterface $entityManagerbool $persistAccessToken)
  17.     {
  18.         $this->entityManager $entityManager;
  19.         $this->persistAccessToken $persistAccessToken;
  20.     }
  21.     public function find(string $identifier): ?AccessTokenInterface
  22.     {
  23.         if (!$this->persistAccessToken) {
  24.             return null;
  25.         }
  26.         return $this->entityManager->find(AccessToken::class, $identifier);
  27.     }
  28.     public function save(AccessTokenInterface $accessToken): void
  29.     {
  30.         if (!$this->persistAccessToken) {
  31.             return;
  32.         }
  33.         $this->entityManager->persist($accessToken);
  34.         $this->entityManager->flush();
  35.     }
  36.     public function clearExpired(): int
  37.     {
  38.         if (!$this->persistAccessToken) {
  39.             return 0;
  40.         }
  41.         /** @var int */
  42.         return $this->entityManager->createQueryBuilder()
  43.             ->delete(AccessToken::class, 'at')
  44.             ->where('at.expiry < :expiry')
  45.             ->setParameter('expiry', new \DateTimeImmutable(), 'datetime_immutable')
  46.             ->getQuery()
  47.             ->execute();
  48.     }
  49. }