1: <?php
2:
3: namespace PHPixie\Slice\Type\ArrayData;
4:
5: class Editable extends \PHPixie\Slice\Type\ArrayData
6: implements \PHPixie\Slice\Data\Editable
7: {
8: 9: 10:
11: public function set($path, $value)
12: {
13: if ($path === null) {
14:
15: if (!is_array($value)) {
16: throw new \PHPixie\Slice\Exception("Only array values can be set as root");
17: }
18: $this->data = $value;
19: return;
20: }
21:
22: list($path, $key) = $this->splitPath($path);
23: $parent = &$this->findGroup($path, true);
24: $parent[$key] = $value;
25: }
26:
27: 28: 29:
30: public function remove($path = null)
31: {
32: if ($path === null) {
33: $this->data = array();
34: return;
35: }
36:
37: list($path, $key) = $this->splitPath($path);
38: $parent = &$this->findGroup($path);
39:
40: if($parent !== null) {
41: unset($parent[$key]);
42: }
43: }
44:
45: 46: 47:
48: public function slice($path = null)
49: {
50: return $this->sliceBuilder->editableSlice($this, $path);
51: }
52: }
53: