1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the API Platform project. |
5
|
|
|
* |
6
|
|
|
* (c) Kévin Dunglas <[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 ApiPlatform\Core\Bridge\Doctrine\Orm\Util; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
17
|
|
|
use Doctrine\Common\Persistence\Mapping\ClassMetadata; |
18
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
19
|
|
|
use Doctrine\ORM\Query\Expr\OrderBy; |
20
|
|
|
use Doctrine\ORM\QueryBuilder; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Utility functions for working with Doctrine ORM query. |
24
|
|
|
* |
25
|
|
|
* @author Teoh Han Hui <[email protected]> |
26
|
|
|
* @author Vincent Chalamon <[email protected]> |
27
|
|
|
* |
28
|
|
|
* @internal |
29
|
|
|
* |
30
|
|
|
* @deprecated |
31
|
|
|
*/ |
32
|
|
|
final class QueryJoinParser |
33
|
|
|
{ |
34
|
|
|
private function __construct() |
35
|
|
|
{ |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Gets the class metadata from a given join alias. |
40
|
|
|
* |
41
|
|
|
* @deprecated |
42
|
|
|
*/ |
43
|
|
|
public static function getClassMetadataFromJoinAlias(string $alias, QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry): ClassMetadata |
44
|
|
|
{ |
45
|
|
|
@trigger_error(sprintf('The use of "%s::getClassMetadataFromJoinAlias()" is deprecated since 2.4 and will be removed in 3.0. Use "%s::getEntityClassByAlias()" instead.', __CLASS__, QueryBuilderHelper::class), E_USER_DEPRECATED); |
46
|
|
|
|
47
|
|
|
$entityClass = QueryBuilderHelper::getEntityClassByAlias($alias, $queryBuilder, $managerRegistry); |
48
|
|
|
|
49
|
|
|
return $managerRegistry |
50
|
|
|
->getManagerForClass($entityClass) |
51
|
|
|
->getClassMetadata($entityClass); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Gets the relationship from a Join expression. |
56
|
|
|
* |
57
|
|
|
* @deprecated |
58
|
|
|
*/ |
59
|
|
|
public static function getJoinRelationship(Join $join): string |
60
|
|
|
{ |
61
|
|
|
@trigger_error(sprintf('The use of "%s::getJoinRelationship()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getJoin()" directly instead.', __CLASS__, Join::class), E_USER_DEPRECATED); |
62
|
|
|
|
63
|
|
|
return $join->getJoin(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Gets the alias from a Join expression. |
68
|
|
|
* |
69
|
|
|
* @deprecated |
70
|
|
|
*/ |
71
|
|
|
public static function getJoinAlias(Join $join): string |
72
|
|
|
{ |
73
|
|
|
@trigger_error(sprintf('The use of "%s::getJoinAlias()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getAlias()" directly instead.', __CLASS__, Join::class), E_USER_DEPRECATED); |
74
|
|
|
|
75
|
|
|
return $join->getAlias(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Gets the parts from an OrderBy expression. |
80
|
|
|
* |
81
|
|
|
* @return string[] |
82
|
|
|
* |
83
|
|
|
* @deprecated |
84
|
|
|
*/ |
85
|
|
|
public static function getOrderByParts(OrderBy $orderBy): array |
86
|
|
|
{ |
87
|
|
|
@trigger_error(sprintf('The use of "%s::getOrderByParts()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getParts()" directly instead.', __CLASS__, OrderBy::class), E_USER_DEPRECATED); |
88
|
|
|
|
89
|
|
|
return $orderBy->getParts(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|