|
13 | 13 | use Nextras\Orm\Relationships\IRelationshipCollection; |
14 | 14 | use Nextras\Orm\Relationships\IRelationshipContainer; |
15 | 15 | use Nextras\Orm\Repository\IRepository; |
| 16 | +use function array_shift; |
16 | 17 | use function assert; |
17 | 18 | use function get_class; |
18 | 19 |
|
@@ -130,23 +131,39 @@ public function setRawValue(string $name, $value): void |
130 | 131 | } |
131 | 132 |
|
132 | 133 |
|
133 | | - public function &getRawValue(string $name) |
| 134 | + public function &getRawValue($name, bool $checkPropertyExistence = false) |
134 | 135 | { |
135 | | - $property = $this->metadata->getProperty($name); |
| 136 | + $path = (array) $name; |
| 137 | + $name = array_shift($path); |
| 138 | + |
| 139 | + if (!$checkPropertyExistence && !$this->metadata->hasProperty($name)) { |
| 140 | + $value = null; |
| 141 | + return $value; |
| 142 | + } |
| 143 | + |
| 144 | + $propertyMetadata = $this->metadata->getProperty($name); |
136 | 145 |
|
137 | 146 | if (!isset($this->validated[$name])) { |
138 | | - $this->initProperty($property, $name); |
| 147 | + $this->initProperty($propertyMetadata, $name); |
139 | 148 | } |
140 | 149 |
|
141 | 150 | $value = $this->data[$name]; |
142 | 151 |
|
143 | | - if ($value instanceof IProperty) { |
| 152 | + if (count($path) > 0) { |
| 153 | + if (!$value instanceof IMultiPropertyPropertyContainer) { |
| 154 | + throw new InvalidStateException("Path to raw value doesn't go through IMultiPropertyPropertyContainer property."); |
| 155 | + } |
| 156 | + |
| 157 | + $value = $value->getRawValueOf($path, $checkPropertyExistence); |
| 158 | + return $value; |
| 159 | + |
| 160 | + } elseif ($value instanceof IProperty) { |
144 | 161 | $value = $value->getRawValue(); |
145 | 162 | return $value; |
146 | 163 | } |
147 | 164 |
|
148 | | - if ($property->isVirtual) { |
149 | | - $value = $this->internalGetValue($property, $name); |
| 165 | + if ($propertyMetadata->isVirtual) { |
| 166 | + $value = $this->internalGetValue($propertyMetadata, $name); |
150 | 167 | return $value; |
151 | 168 | } |
152 | 169 |
|
@@ -229,18 +246,18 @@ public function __clone() |
229 | 246 | $this->data['id'] = null; |
230 | 247 | $this->persistedId = null; |
231 | 248 | $this->data[$name] = clone $this->data[$name]; |
232 | | - $this->data[$name]->setPropertyEntity($this); |
| 249 | + $this->data[$name]->onAttach($this, $metadataProperty); |
233 | 250 | $this->data[$name]->set($data); |
234 | 251 | $this->data['id'] = $id; |
235 | 252 | $this->persistedId = $persistedId; |
236 | 253 |
|
237 | 254 | } elseif ($this->data[$name] instanceof IRelationshipContainer) { |
238 | 255 | $this->data[$name] = clone $this->data[$name]; |
239 | | - $this->data[$name]->setPropertyEntity($this); |
| 256 | + $this->data[$name]->onAttach($this, $metadataProperty); |
240 | 257 |
|
241 | 258 | } elseif ($this->data[$name] instanceof EmbeddableContainer) { |
242 | 259 | $this->data[$name] = clone $this->data[$name]; |
243 | | - $this->data[$name]->setPropertyEntity($this); |
| 260 | + $this->data[$name]->onAttach($this, $metadataProperty); |
244 | 261 |
|
245 | 262 | } else { |
246 | 263 | $this->data[$name] = clone $this->data[$name]; |
@@ -499,7 +516,7 @@ private function createPropertyWrapper(PropertyMetadata $metadata): IProperty |
499 | 516 | assert($wrapper instanceof IProperty); |
500 | 517 |
|
501 | 518 | if ($wrapper instanceof IEntityAwareProperty) { |
502 | | - $wrapper->setPropertyEntity($this); |
| 519 | + $wrapper->onAttach($this, $metadata); |
503 | 520 | } |
504 | 521 |
|
505 | 522 | return $wrapper; |
|
0 commit comments