|
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\ORM\Query\Expr\Join; |
|
18
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
|
19
|
|
|
use Ramsey\Uuid\Exception\InvalidUuidStringException; |
|
20
|
|
|
use Ramsey\Uuid\Uuid; |
|
21
|
|
|
use Silverback\ApiComponentsBundle\Entity\Core\AbstractPageData; |
|
22
|
|
|
use Silverback\ApiComponentsBundle\Entity\Core\Route; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Daniel West <[email protected]> |
|
26
|
|
|
* |
|
27
|
|
|
* @method Route|null find($id, $lockMode = null, $lockVersion = null) |
|
28
|
|
|
* @method Route|null findOneBy(array $criteria, array $orderBy = null) |
|
29
|
|
|
* @method Route[] findAll() |
|
30
|
|
|
* @method Route[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
31
|
|
|
*/ |
|
32
|
|
|
class RouteRepository extends ServiceEntityRepository |
|
33
|
|
|
{ |
|
34
|
|
|
public function __construct(ManagerRegistry $registry) |
|
35
|
|
|
{ |
|
36
|
|
|
parent::__construct($registry, Route::class); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function findOneByIdOrPath(string $idOrRoute): ?Route |
|
40
|
|
|
{ |
|
41
|
|
|
$route = $this->findOneBy( |
|
42
|
|
|
[ |
|
43
|
|
|
'path' => $idOrRoute, |
|
44
|
|
|
] |
|
45
|
|
|
); |
|
46
|
|
|
if ($route) { |
|
47
|
|
|
return $route; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
try { |
|
51
|
|
|
$uuid = Uuid::fromString($idOrRoute); |
|
52
|
|
|
|
|
53
|
|
|
return $this->find($uuid); |
|
54
|
|
|
} catch (InvalidUuidStringException $e) { |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return null; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return Route[] |
|
62
|
|
|
*/ |
|
63
|
|
|
public function findByPageData(AbstractPageData $pageData): array |
|
64
|
|
|
{ |
|
65
|
|
|
$queryBuilder = $this->createQueryBuilder('route'); |
|
66
|
|
|
$queryBuilder |
|
67
|
|
|
->leftJoin( |
|
68
|
|
|
'route.pageData', |
|
69
|
|
|
'pageData', |
|
70
|
|
|
Join::WITH, |
|
71
|
|
|
$queryBuilder->expr()->eq('route', 'pageData.route') |
|
72
|
|
|
) |
|
73
|
|
|
->andWhere($queryBuilder->expr()->eq('pageData', ':page_data')) |
|
74
|
|
|
->setParameter('page_data', $pageData); |
|
75
|
|
|
|
|
76
|
|
|
return $queryBuilder->getQuery()->getResult(); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function findConflicts(string $name, string $path): array |
|
80
|
|
|
{ |
|
81
|
|
|
$queryBuilder = $this->createQueryBuilder('route'); |
|
82
|
|
|
$expr = $queryBuilder->expr(); |
|
83
|
|
|
$queryBuilder |
|
84
|
|
|
->andWhere($expr->orX( |
|
85
|
|
|
$expr->like('route.path', ':path'), |
|
86
|
|
|
$expr->like('route.name', ':name'), |
|
87
|
|
|
)) |
|
88
|
|
|
->setParameter('path', $path . '%') |
|
89
|
|
|
->setParameter('name', $name . '%'); |
|
90
|
|
|
|
|
91
|
|
|
return $queryBuilder->getQuery()->getResult(); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|