1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Iterator; |
4: | |
5: | use Salient\Iterator\Contract\MutableIterator; |
6: | use LogicException; |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | class MutableGraphIterator extends GraphIterator implements MutableIterator |
17: | { |
18: | |
19: | |
20: | |
21: | public function __construct(&$graph) |
22: | { |
23: | $this->doConstruct($graph); |
24: | } |
25: | |
26: | |
27: | |
28: | |
29: | public function replace($value) |
30: | { |
31: | $key = current($this->Keys); |
32: | if ($key === false) { |
33: | |
34: | throw new LogicException('Current position is not valid'); |
35: | |
36: | } |
37: | |
38: | if ($this->IsObject) { |
39: | $this->Graph->{$key} = $value; |
40: | return $this; |
41: | } |
42: | |
43: | |
44: | $this->Graph[$key] = $value; |
45: | return $this; |
46: | } |
47: | } |
48: | |