1 | <?php |
||
14 | final class Pointer |
||
15 | { |
||
16 | /** |
||
17 | * @var object|array |
||
18 | */ |
||
19 | private $json; |
||
20 | |||
21 | /** |
||
22 | * @param object|array $json |
||
23 | */ |
||
24 | 90 | public function __construct(&$json) |
|
28 | |||
29 | /** |
||
30 | * @param string $pointer |
||
31 | * |
||
32 | * @return mixed |
||
33 | * |
||
34 | * @throws InvalidPointerException |
||
35 | */ |
||
36 | 58 | public function get($pointer) |
|
46 | |||
47 | /** |
||
48 | * @param string $pointer |
||
49 | * |
||
50 | * @return mixed |
||
51 | */ |
||
52 | 68 | public function getRaw($pointer) |
|
58 | |||
59 | /** |
||
60 | * @param string $pointer |
||
61 | * |
||
62 | * @return bool |
||
63 | */ |
||
64 | 54 | public function has($pointer) |
|
68 | |||
69 | /** |
||
70 | * @param string $pointer |
||
71 | * @param mixed $data |
||
72 | * |
||
73 | * @return void |
||
74 | * |
||
75 | * @throws InvalidPointerException |
||
76 | * @throws \InvalidArgumentException |
||
77 | * |
||
78 | */ |
||
79 | 58 | public function set($pointer, $data) |
|
101 | |||
102 | /** |
||
103 | * @param string $pointer |
||
104 | * |
||
105 | * @return void |
||
106 | */ |
||
107 | 12 | public function remove($pointer) |
|
125 | |||
126 | /** |
||
127 | * @param array $pointer |
||
128 | * |
||
129 | * @return mixed |
||
130 | */ |
||
131 | 64 | private function &getTarget(array $pointer) |
|
145 | |||
146 | /** |
||
147 | * @param mixed $json The result of a json_decode call or a portion of it. |
||
148 | * @param array $pointer The parsed pointer |
||
149 | * |
||
150 | * @return mixed |
||
151 | */ |
||
152 | 66 | private function traverse($json, $pointer) |
|
181 | |||
182 | /** |
||
183 | * Parses a JSON Pointer as defined in the specification. |
||
184 | * @see https://tools.ietf.org/html/rfc6901#section-4 |
||
185 | * |
||
186 | * @param string $pointer |
||
187 | * |
||
188 | * @return array |
||
189 | * |
||
190 | * @throws InvalidPointerException |
||
191 | */ |
||
192 | 86 | private function parse($pointer) |
|
215 | } |
||
216 |