1 | <?php |
||
28 | class Document implements JsonSerializable |
||
29 | { |
||
30 | private static $PATH_ID = '_meta.id'; |
||
31 | |||
32 | private $data; |
||
33 | |||
34 | |||
35 | |||
36 | /** |
||
37 | * @param array $data |
||
38 | */ |
||
39 | public function __construct($data = array()) |
||
43 | |||
44 | |||
45 | |||
46 | /** |
||
47 | * @param string $path 'comma.separated.path.to.value' |
||
48 | * @return boolean |
||
49 | */ |
||
50 | public function has($path) |
||
67 | |||
68 | |||
69 | |||
70 | /** |
||
71 | * @param string $path 'comma.separated.path.to.value' |
||
72 | * @return array|mixed |
||
73 | */ |
||
74 | public function get($path) |
||
85 | |||
86 | |||
87 | |||
88 | /** |
||
89 | * This method allows you to set a value in the document by using this syntax: |
||
90 | * |
||
91 | * set('path.to.level', 'myValue') |
||
92 | * |
||
93 | * ... does nothing else than ... |
||
94 | * |
||
95 | * document[path][to][level] = 'myValue' |
||
96 | * |
||
97 | * Because the path is translated into an array structure in interations |
||
98 | * we need to store the reference to each intermediate array field |
||
99 | * for usage in the next iteration. |
||
100 | * |
||
101 | * @param string $path 'comma.separated.path.to.value' |
||
102 | * @param mixed $value The value to store |
||
103 | * @return boolean |
||
104 | */ |
||
105 | public function set($path, $value) |
||
125 | |||
126 | |||
127 | |||
128 | public function hasId(): bool |
||
132 | |||
133 | |||
134 | |||
135 | public function getId(): string |
||
139 | |||
140 | |||
141 | |||
142 | public function setId(string $id) |
||
146 | |||
147 | |||
148 | |||
149 | public function toArray() |
||
153 | |||
154 | |||
155 | /** |
||
156 | * @param string $path |
||
157 | * @return array |
||
158 | */ |
||
159 | private function getPathSegments($path) |
||
166 | |||
167 | |||
168 | |||
169 | public function jsonSerialize() |
||
173 | } |
||
174 |