1: <?php declare(strict_types=1);
2:
3: namespace Salient\Iterator;
4:
5: use RecursiveIterator;
6:
7: /**
8: * Iterates over nested arrays and objects
9: *
10: * @api
11: *
12: * @implements RecursiveIterator<array-key,mixed>
13: */
14: class RecursiveGraphIterator extends GraphIterator implements RecursiveIterator
15: {
16: /**
17: * @api
18: *
19: * @param mixed[]|object $value
20: */
21: final public function __construct(&$value)
22: {
23: parent::__construct($value);
24: }
25:
26: /**
27: * @inheritDoc
28: */
29: public function hasChildren(): bool
30: {
31: return is_object($current = $this->current()) || is_array($current);
32: }
33:
34: /**
35: * @inheritDoc
36: */
37: public function getChildren(): ?self
38: {
39: if (($key = $this->key()) !== null) {
40: if ($this->IsObject) {
41: $current = &$this->Object->{$key};
42: } else {
43: $current = &$this->Array[$key];
44: }
45: if (is_object($current) || is_array($current)) {
46: return new static($current);
47: }
48: }
49: return null;
50: }
51: }
52: