1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the G.L.S.R. Apps package. |
7
|
|
|
* |
8
|
|
|
* (c) Dev-Int Création <[email protected]>. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Administration\Infrastructure\Persistence\DoctrineOrm\Repositories; |
15
|
|
|
|
16
|
|
|
use Administration\Domain\Protocol\Repository\UserRepositoryProtocol; |
17
|
|
|
use Administration\Domain\User\Model\User; |
18
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
19
|
|
|
use Doctrine\ORM\NonUniqueResultException; |
20
|
|
|
use Doctrine\ORM\OptimisticLockException; |
21
|
|
|
use Doctrine\ORM\ORMException; |
22
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
23
|
|
|
|
24
|
|
|
class DoctrineUserRepository extends ServiceEntityRepository implements UserRepositoryProtocol |
25
|
|
|
{ |
26
|
|
|
public function __construct(ManagerRegistry $registry) |
27
|
|
|
{ |
28
|
|
|
parent::__construct($registry, User::class); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @throws ORMException |
33
|
|
|
* @throws OptimisticLockException |
34
|
|
|
*/ |
35
|
|
|
final public function add(User $user): void |
36
|
|
|
{ |
37
|
|
|
$this->getEntityManager()->persist($user); |
38
|
|
|
$this->getEntityManager()->flush(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @throws ORMException |
43
|
|
|
*/ |
44
|
|
|
final public function remove(User $user): void |
45
|
|
|
{ |
46
|
|
|
$this->getEntityManager()->remove($user); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @throws NonUniqueResultException |
51
|
|
|
*/ |
52
|
|
|
final public function findOneByUuid(string $uuid): ?User |
53
|
|
|
{ |
54
|
|
|
return $this->createQueryBuilder('u') |
55
|
|
|
->where('u.uuid = :uuid') |
56
|
|
|
->setParameter('uuid', $uuid) |
57
|
|
|
->getQuery() |
58
|
|
|
->getOneOrNullResult() |
59
|
|
|
; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @throws NonUniqueResultException |
64
|
|
|
*/ |
65
|
|
|
final public function existWithUsername(string $username): bool |
66
|
|
|
{ |
67
|
|
|
$statement = $this->createQueryBuilder('u') |
68
|
|
|
->select(['1']) |
69
|
|
|
->where('u.username = :username') |
70
|
|
|
->setParameter('username', $username) |
71
|
|
|
->getQuery() |
72
|
|
|
->getOneOrNullResult() |
73
|
|
|
; |
74
|
|
|
|
75
|
|
|
return !(null === $statement); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @throws NonUniqueResultException |
80
|
|
|
*/ |
81
|
|
|
final public function existWithEmail(string $email): bool |
82
|
|
|
{ |
83
|
|
|
$statement = $this->createQueryBuilder('u') |
84
|
|
|
->select(['1']) |
85
|
|
|
->where('u.email = :email') |
86
|
|
|
->setParameter('email', $email) |
87
|
|
|
->getQuery() |
88
|
|
|
->getOneOrNullResult() |
89
|
|
|
; |
90
|
|
|
|
91
|
|
|
return !(null === $statement); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|