1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Users\Repository; |
6
|
|
|
|
7
|
|
|
use App\Users\Entity\ConfirmationToken; |
8
|
|
|
use App\Users\Entity\User; |
9
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
10
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @method ConfirmationToken|null find($id, $lockMode = null, $lockVersion = null) |
14
|
|
|
* @method ConfirmationToken|null findOneBy(array $criteria, array $orderBy = null) |
15
|
|
|
* @method ConfirmationToken[] findAll() |
16
|
|
|
* @method ConfirmationToken[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
17
|
|
|
*/ |
18
|
|
|
class ConfirmationTokenRepository extends ServiceEntityRepository |
19
|
|
|
{ |
20
|
10 |
|
public function __construct(RegistryInterface $registry) |
21
|
|
|
{ |
22
|
10 |
|
parent::__construct($registry, ConfirmationToken::class); |
23
|
10 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $token |
27
|
|
|
* |
28
|
|
|
* @throws \Doctrine\ORM\NonUniqueResultException |
29
|
|
|
* |
30
|
|
|
* @return ConfirmationToken|null |
31
|
|
|
*/ |
32
|
5 |
|
public function findByToken(string $token): ?ConfirmationToken |
33
|
|
|
{ |
34
|
5 |
|
return $this->createQueryBuilder('t') |
35
|
5 |
|
->select('t') |
36
|
5 |
|
->where('t.token = :token AND t.expires_at >= :now') |
37
|
5 |
|
->setParameter('token', $token) |
38
|
5 |
|
->setParameter('now', new \DateTime()) |
39
|
5 |
|
->getQuery() |
40
|
5 |
|
->getOneOrNullResult(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param User $user |
45
|
|
|
* @param string $type |
46
|
|
|
* |
47
|
|
|
* @throws \Doctrine\ORM\NonUniqueResultException |
48
|
|
|
* |
49
|
|
|
* @return ConfirmationToken|null |
50
|
|
|
*/ |
51
|
1 |
|
public function findByUserAndType(User $user, string $type): ?ConfirmationToken |
52
|
|
|
{ |
53
|
1 |
|
return $this->createQueryBuilder('t') |
54
|
1 |
|
->select('t') |
55
|
1 |
|
->where('t.user = :user AND t.type = :type AND t.expires_at >= :now') |
56
|
1 |
|
->setParameter('user', $user->getId()) |
57
|
1 |
|
->setParameter('type', $type) |
58
|
1 |
|
->setParameter('now', new \DateTime()) |
59
|
1 |
|
->getQuery() |
60
|
1 |
|
->getOneOrNullResult(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|