|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Daniel West <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Silverback\ApiComponentsBundle\Repository\Core; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|
17
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
|
18
|
|
|
use Silverback\ApiComponentsBundle\Entity\Core\AbstractRefreshToken; |
|
19
|
|
|
use Silverback\ApiComponentsBundle\Exception\InvalidArgumentException; |
|
20
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @author Daniel West <[email protected]> |
|
24
|
|
|
* |
|
25
|
|
|
* @method AbstractRefreshToken|null find($id, $lockMode = null, $lockVersion = null) |
|
26
|
|
|
* @method AbstractRefreshToken|null findOneBy(array $criteria, array $orderBy = null) |
|
27
|
|
|
* @method AbstractRefreshToken[] findAll() |
|
28
|
|
|
* @method AbstractRefreshToken[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
29
|
|
|
*/ |
|
30
|
|
|
class RefreshTokenRepository extends ServiceEntityRepository |
|
31
|
|
|
{ |
|
32
|
|
|
public function __construct(ManagerRegistry $registry, string $entityClass) |
|
33
|
|
|
{ |
|
34
|
|
|
if (!is_subclass_of($entityClass, AbstractRefreshToken::class)) { |
|
35
|
|
|
throw new InvalidArgumentException(sprintf('The entity class `%s` used for the repository `%s` must be a subclass of `%s`', $entityClass, __CLASS__, AbstractRefreshToken::class)); |
|
36
|
|
|
} |
|
37
|
|
|
parent::__construct($registry, $entityClass); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return AbstractRefreshToken[] |
|
42
|
|
|
*/ |
|
43
|
|
|
public function findByUser(UserInterface $user): array |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->createQueryBuilder('rt') |
|
46
|
|
|
->andWhere('rt.user = :user')->setParameter('user', $user) |
|
47
|
|
|
->andWhere('rt.expiresAt > :now')->setParameter('now', new \DateTimeImmutable()) |
|
48
|
|
|
->getQuery() |
|
49
|
|
|
->getResult(); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|