|
14 | 14 |
|
15 | 15 | use bdk\Debug\Abstraction\Abstracter; |
16 | 16 | use bdk\Debug\Abstraction\Abstraction as BaseAbstraction; |
| 17 | +use bdk\Debug\Abstraction\AbstractObject; |
| 18 | +use bdk\Debug\Abstraction\Object\Constants; |
| 19 | +use bdk\Debug\Abstraction\Object\Definition; |
| 20 | +use bdk\Debug\Abstraction\Object\MethodParams; |
| 21 | +use bdk\Debug\Abstraction\Object\Methods; |
| 22 | +use bdk\Debug\Abstraction\Object\Properties; |
17 | 23 | use bdk\Debug\Abstraction\Type; |
18 | 24 | use bdk\Debug\Utility\ArrayUtil; |
19 | 25 | use bdk\PubSub\ValueStore; |
@@ -80,9 +86,8 @@ public function __toString() |
80 | 86 | */ |
81 | 87 | public function __unserialize(array $data) |
82 | 88 | { |
83 | | - $this->inherited = isset($data['inherited']) |
84 | | - ? $data['inherited'] |
85 | | - : new ValueStore(); |
| 89 | + $data = $this->unserializeDataPrep($data); |
| 90 | + $this->inherited = $data['inherited']; |
86 | 91 | unset($data['inherited']); |
87 | 92 | $this->values = $data; |
88 | 93 | } |
@@ -209,11 +214,42 @@ public function offsetExists($key) |
209 | 214 | #[\ReturnTypeWillChange] |
210 | 215 | public function &offsetGet($key) |
211 | 216 | { |
| 217 | + if ($key === 'inherited') { |
| 218 | + return $this->inherited; |
| 219 | + } |
212 | 220 | // update our local and return it as a reference |
213 | 221 | $this->values[$key] = $this->getCombinedValue($key); |
214 | 222 | return $this->values[$key]; |
215 | 223 | } |
216 | 224 |
|
| 225 | + /** |
| 226 | + * Make sure property and method info contains expected keys |
| 227 | + * |
| 228 | + * @param \ArrayAccess $data Either instance data or inherited data |
| 229 | + * |
| 230 | + * @return array |
| 231 | + */ |
| 232 | + public static function unserializeBuildValues($data) |
| 233 | + { |
| 234 | + $data['constants'] = \array_map(static function (array $info) { |
| 235 | + return Constants::buildValues($info); |
| 236 | + }, $data['constants']); |
| 237 | + |
| 238 | + $data['properties'] = \array_map(static function (array $info) { |
| 239 | + return Properties::buildValues($info); |
| 240 | + }, $data['properties']); |
| 241 | + |
| 242 | + $data['methods'] = \array_map(static function (array $info) { |
| 243 | + $info = Methods::buildValues($info); |
| 244 | + $info['params'] = \array_map(static function (array $paramInfo) { |
| 245 | + return MethodParams::buildValues($paramInfo); |
| 246 | + }, $info['params']); |
| 247 | + return $info; |
| 248 | + }, $data['methods']); |
| 249 | + |
| 250 | + return $data; |
| 251 | + } |
| 252 | + |
217 | 253 | /** |
218 | 254 | * Get merged class & instance value |
219 | 255 | * |
@@ -299,4 +335,52 @@ protected function sortData(array $array) |
299 | 335 | } |
300 | 336 | return $sortData; |
301 | 337 | } |
| 338 | + |
| 339 | + /** |
| 340 | + * Ensure data contains all expected keys |
| 341 | + * |
| 342 | + * @param array $data Serialized data |
| 343 | + * |
| 344 | + * @return array |
| 345 | + */ |
| 346 | + private function unserializeDataPrep(array $data) |
| 347 | + { |
| 348 | + if (empty($data['definition'])) { |
| 349 | + // we are instance values |
| 350 | + $data = AbstractObject::buildValues($data); |
| 351 | + } |
| 352 | + |
| 353 | + if (empty($data['className'])) { |
| 354 | + unset($data['className']); |
| 355 | + } |
| 356 | + |
| 357 | + $data['inherited'] = $this->unserializeDataInherited($data); |
| 358 | + |
| 359 | + return $data; |
| 360 | + } |
| 361 | + |
| 362 | + /** |
| 363 | + * Get inherited ValueStore |
| 364 | + * |
| 365 | + * @param array $data Serialized data |
| 366 | + * |
| 367 | + * @return ValueStore |
| 368 | + */ |
| 369 | + private function unserializeDataInherited(array &$data) |
| 370 | + { |
| 371 | + if (isset($data['inherited'])) { |
| 372 | + $inherited = $data['inherited']; |
| 373 | + unset($data['inherited']); |
| 374 | + return $this->unserializeBuildValues($inherited); |
| 375 | + } |
| 376 | + if (isset($data['classDefinition'])) { |
| 377 | + // maintain backwards compatibility - v3.1 used 'classDefinition' |
| 378 | + $inherited = $data['classDefinition']; |
| 379 | + unset($data['classDefinition']); |
| 380 | + return $this->unserializeBuildValues($inherited); |
| 381 | + } |
| 382 | + // maintain backwards compatibility - v3.0 did not inherit |
| 383 | + $data = $this->unserializeBuildValues($data); |
| 384 | + return new ValueStore(AbstractObject::buildValues(Definition::buildValues())); |
| 385 | + } |
302 | 386 | } |
0 commit comments