1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Iterator; |
4: | |
5: | use Salient\Iterator\Concern\RecursiveGraphIteratorTrait; |
6: | use RecursiveIterator; |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | class RecursiveMutableGraphIterator extends MutableGraphIterator implements RecursiveIterator |
18: | { |
19: | use RecursiveGraphIteratorTrait; |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | public function maybeConvertToArray() |
28: | { |
29: | $current = $this->current(); |
30: | if ($current === false) { |
31: | |
32: | return $this; |
33: | |
34: | } |
35: | |
36: | if (is_object($current) && $this->hasChildren()) { |
37: | $array = []; |
38: | |
39: | foreach ($current as $key => $value) { |
40: | $array[$key] = $value; |
41: | } |
42: | |
43: | return $this->replace($array); |
44: | } |
45: | |
46: | return $this; |
47: | } |
48: | } |
49: | |