1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace Doctrine\ORM\Mapping; |
||||
6 | |||||
7 | use ArrayIterator; |
||||
8 | use Doctrine\ORM\Reflection\ReflectionService; |
||||
9 | use ReflectionClass; |
||||
10 | use ReflectionException; |
||||
11 | |||||
12 | /** |
||||
13 | * A <tt>ComponentMetadata</tt> instance holds object-relational property mapping. |
||||
14 | */ |
||||
15 | abstract class ComponentMetadata |
||||
16 | { |
||||
17 | /** @var string */ |
||||
18 | protected $className; |
||||
19 | |||||
20 | /** @var ComponentMetadata|null */ |
||||
21 | protected $parent; |
||||
22 | |||||
23 | /** |
||||
24 | * The ReflectionClass instance of the component class. |
||||
25 | * |
||||
26 | * @var ReflectionClass|null |
||||
27 | */ |
||||
28 | protected $reflectionClass; |
||||
29 | |||||
30 | /** @var CacheMetadata|null */ |
||||
31 | protected $cache; |
||||
32 | |||||
33 | /** @var Property[] */ |
||||
34 | protected $properties = []; |
||||
35 | |||||
36 | 450 | public function __construct(string $className) |
|||
37 | { |
||||
38 | 450 | $this->className = $className; |
|||
39 | 450 | } |
|||
40 | |||||
41 | 2021 | public function getClassName() : string |
|||
42 | { |
||||
43 | 2021 | return $this->className; |
|||
44 | } |
||||
45 | |||||
46 | 99 | public function setParent(ComponentMetadata $parent) : void |
|||
47 | { |
||||
48 | 99 | $this->parent = $parent; |
|||
49 | 99 | } |
|||
50 | |||||
51 | 1218 | public function getParent() : ?ComponentMetadata |
|||
52 | { |
||||
53 | 1218 | return $this->parent; |
|||
54 | } |
||||
55 | |||||
56 | 1959 | public function wakeupReflection(ReflectionService $reflectionService) : void |
|||
57 | { |
||||
58 | // Restore ReflectionClass and properties |
||||
59 | 1959 | $this->reflectionClass = $reflectionService->getClass($this->className); |
|||
60 | |||||
61 | 1959 | if (! $this->reflectionClass) { |
|||
62 | return; |
||||
63 | } |
||||
64 | |||||
65 | 1959 | $this->className = $this->reflectionClass->getName(); |
|||
66 | |||||
67 | 1959 | foreach ($this->properties as $property) { |
|||
68 | /** @var Property $property */ |
||||
69 | 1956 | $property->wakeupReflection($reflectionService); |
|||
70 | } |
||||
71 | 1959 | } |
|||
72 | |||||
73 | 541 | public function getReflectionClass() : ?ReflectionClass |
|||
74 | { |
||||
75 | 541 | return $this->reflectionClass; |
|||
76 | } |
||||
77 | |||||
78 | 25 | public function setCache(?CacheMetadata $cache = null) : void |
|||
79 | { |
||||
80 | 25 | $this->cache = $cache; |
|||
81 | 25 | } |
|||
82 | |||||
83 | 181 | public function getCache() : ?CacheMetadata |
|||
84 | { |
||||
85 | 181 | return $this->cache; |
|||
86 | } |
||||
87 | |||||
88 | /** |
||||
89 | * @return iterable|Property[] |
||||
90 | */ |
||||
91 | 1488 | public function getPropertiesIterator() : iterable |
|||
92 | { |
||||
93 | 1488 | foreach ($this->properties as $name => $property) { |
|||
94 | 1487 | yield $name => $property; |
|||
95 | } |
||||
96 | 1487 | } |
|||
97 | |||||
98 | /** |
||||
99 | * @throws ReflectionException |
||||
100 | * @throws MappingException |
||||
101 | */ |
||||
102 | 417 | public function addProperty(Property $property) : void |
|||
103 | { |
||||
104 | 417 | $className = $this->getClassName(); |
|||
105 | 417 | $propertyName = $property->getName(); |
|||
106 | |||||
107 | 417 | if ($this->hasProperty($propertyName)) { |
|||
108 | 2 | throw MappingException::duplicateProperty($className, $this->getProperty($propertyName)); |
|||
109 | } |
||||
110 | |||||
111 | 417 | $property->setDeclaringClass($this); |
|||
112 | |||||
113 | 417 | $this->properties[$propertyName] = $property; |
|||
114 | 417 | } |
|||
115 | |||||
116 | 417 | public function hasProperty(string $propertyName) : bool |
|||
117 | { |
||||
118 | 417 | return isset($this->properties[$propertyName]); |
|||
119 | } |
||||
120 | |||||
121 | 1813 | public function getProperty(string $propertyName) : ?Property |
|||
122 | { |
||||
123 | 1813 | if (isset($this->properties[$propertyName])) { |
|||
124 | 1806 | return $this->properties[$propertyName]; |
|||
125 | } |
||||
126 | |||||
127 | 522 | return null; |
|||
128 | } |
||||
129 | |||||
130 | /** |
||||
131 | * @return ArrayIterator|ColumnMetadata[] |
||||
132 | */ |
||||
133 | public function getColumnsIterator() : ArrayIterator |
||||
134 | { |
||||
135 | $iterator = new ArrayIterator(); |
||||
136 | |||||
137 | foreach ($this->getPropertiesIterator() as $property) { |
||||
138 | switch (true) { |
||||
139 | case $property instanceof FieldMetadata: |
||||
140 | $iterator->offsetSet($property->getColumnName(), $property); |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
141 | break; |
||||
142 | |||||
143 | case $property instanceof ToOneAssociationMetadata && $property->isOwningSide(): |
||||
144 | foreach ($property->getJoinColumns() as $joinColumn) { |
||||
0 ignored issues
–
show
The method
getJoinColumns() does not exist on Doctrine\ORM\Mapping\Property . It seems like you code against a sub-type of Doctrine\ORM\Mapping\Property such as Doctrine\ORM\Mapping\ToOneAssociationMetadata .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
145 | /** @var JoinColumnMetadata $joinColumn */ |
||||
146 | $iterator->offsetSet($joinColumn->getColumnName(), $joinColumn); |
||||
0 ignored issues
–
show
$joinColumn of type Doctrine\ORM\Mapping\JoinColumnMetadata is incompatible with the type string expected by parameter $newval of ArrayIterator::offsetSet() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
147 | } |
||||
148 | |||||
149 | break; |
||||
150 | } |
||||
151 | } |
||||
152 | |||||
153 | return $iterator; |
||||
154 | } |
||||
155 | } |
||||
156 |