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