1 | <?php |
||
26 | class Document |
||
27 | { |
||
28 | private $data; |
||
29 | |||
30 | |||
31 | |||
32 | /** |
||
33 | * @param array $data |
||
34 | */ |
||
35 | public function __construct($data = array()) |
||
36 | { |
||
37 | $this->data = $data; |
||
38 | } |
||
39 | |||
40 | |||
41 | |||
42 | /** |
||
43 | * @param string $path 'comma.separated.path.to.value' |
||
44 | * @return boolean |
||
45 | */ |
||
46 | public function has($path) |
||
63 | |||
64 | |||
65 | |||
66 | /** |
||
67 | * @param string $path 'comma.separated.path.to.value' |
||
68 | * @return array|mixed |
||
69 | */ |
||
70 | public function get($path) |
||
81 | |||
82 | |||
83 | |||
84 | /** |
||
85 | * This method allows you to set a value in the document by using this syntax: |
||
86 | * |
||
87 | * set('path.to.level', 'myValue') |
||
88 | * |
||
89 | * ... does nothing else than ... |
||
90 | * |
||
91 | * document[path][to][level] = 'myValue' |
||
92 | * |
||
93 | * Because the path is translated into an array structure in interations |
||
94 | * we need to store the reference to each intermediate array field |
||
95 | * for usage in the next iteration. |
||
96 | * |
||
97 | * @param string $path 'comma.separated.path.to.value' |
||
98 | * @param mixed $value The value to store |
||
99 | * @return boolean |
||
100 | */ |
||
101 | public function set($path, $value) |
||
121 | |||
122 | |||
123 | |||
124 | public function toJson() |
||
128 | |||
129 | |||
130 | |||
131 | public function toArray() |
||
135 | |||
136 | |||
137 | /** |
||
138 | * @param string $path |
||
139 | * @return array |
||
140 | */ |
||
141 | private function getPathSegments($path) |
||
148 | } |
||
149 |