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\Company\Model\Company; |
17
|
|
|
use Administration\Domain\Protocol\Repository\CompanyRepositoryProtocol; |
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 DoctrineCompanyRepository extends ServiceEntityRepository implements CompanyRepositoryProtocol |
25
|
|
|
{ |
26
|
|
|
public function __construct(ManagerRegistry $registry) |
27
|
|
|
{ |
28
|
|
|
parent::__construct($registry, Company::class); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @throws NonUniqueResultException |
33
|
|
|
*/ |
34
|
|
|
final public function existsWithName(string $name): bool |
35
|
|
|
{ |
36
|
|
|
$statement = $this->createQueryBuilder('c') |
37
|
|
|
->select(['1']) |
38
|
|
|
->where('c.name = :name') |
39
|
|
|
->setParameter('name', $name) |
40
|
|
|
->getQuery() |
41
|
|
|
->getOneOrNullResult() |
42
|
|
|
; |
43
|
|
|
|
44
|
|
|
return !(null === $statement); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @throws ORMException |
49
|
|
|
* @throws OptimisticLockException |
50
|
|
|
*/ |
51
|
|
|
final public function add(Company $company): void |
52
|
|
|
{ |
53
|
|
|
$this->getEntityManager()->persist($company); |
54
|
|
|
$this->getEntityManager()->flush(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @throws ORMException |
59
|
|
|
*/ |
60
|
|
|
final public function remove(Company $company): void |
61
|
|
|
{ |
62
|
|
|
$this->getEntityManager()->remove($company); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @throws NonUniqueResultException |
67
|
|
|
*/ |
68
|
|
|
final public function findOneByUuid(string $uuid): ?Company |
69
|
|
|
{ |
70
|
|
|
return $this->createQueryBuilder('c') |
71
|
|
|
->where('c.uuid = :uuid') |
72
|
|
|
->setParameter('uuid', $uuid) |
73
|
|
|
->getQuery() |
74
|
|
|
->getOneOrNullResult() |
75
|
|
|
; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @throws NonUniqueResultException |
80
|
|
|
*/ |
81
|
|
|
final public function companyExist(): bool |
82
|
|
|
{ |
83
|
|
|
$statement = $this->createQueryBuilder('c') |
84
|
|
|
->getQuery() |
85
|
|
|
->getOneOrNullResult() |
86
|
|
|
; |
87
|
|
|
|
88
|
|
|
return null !== $statement; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|