1 | <?php |
||
2 | |||
3 | namespace Doctrine\ORM\Utility; |
||
4 | |||
5 | use Doctrine\Common\Persistence\Mapping\ClassMetadata; |
||
6 | use Doctrine\ORM\EntityManagerInterface; |
||
7 | |||
8 | /** |
||
9 | * @internal This class exists only to avoid code duplication, do not reuse it externally |
||
10 | */ |
||
11 | final class HierarchyDiscriminatorResolver |
||
12 | { |
||
13 | private function __construct() |
||
14 | { |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * This method is needed to make INSTANCEOF work correctly with inheritance: if the class at hand has inheritance, |
||
19 | * it extracts all the discriminators from the child classes and returns them |
||
20 | */ |
||
21 | 14 | public static function resolveDiscriminatorsForClass( |
|
22 | ClassMetadata $rootClassMetadata, |
||
23 | EntityManagerInterface $entityManager |
||
24 | ): array { |
||
25 | 14 | $hierarchyClasses = $rootClassMetadata->subClasses; |
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
26 | 14 | $hierarchyClasses[] = $rootClassMetadata->name; |
|
0 ignored issues
–
show
|
|||
27 | |||
28 | 14 | $discriminators = []; |
|
29 | |||
30 | 14 | foreach ($hierarchyClasses as $class) { |
|
31 | 14 | $currentMetadata = $entityManager->getClassMetadata($class); |
|
32 | 14 | $currentDiscriminator = $currentMetadata->discriminatorValue; |
|
0 ignored issues
–
show
|
|||
33 | |||
34 | 14 | if (null !== $currentDiscriminator) { |
|
35 | 14 | $discriminators[$currentDiscriminator] = null; |
|
36 | } |
||
37 | } |
||
38 | |||
39 | 14 | return $discriminators; |
|
40 | } |
||
41 | } |
||
42 |