1 | <?php |
||
8 | class Json |
||
9 | { |
||
10 | /** |
||
11 | * The file path. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $path; |
||
16 | |||
17 | /** |
||
18 | * The laravel filesystem instance. |
||
19 | * |
||
20 | * @var \Illuminate\Filesystem\Filesystem |
||
21 | */ |
||
22 | protected $filesystem; |
||
23 | |||
24 | /** |
||
25 | * The attributes collection. |
||
26 | * |
||
27 | * @var \Illuminate\Support\Collection |
||
28 | */ |
||
29 | protected $attributes; |
||
30 | |||
31 | /** |
||
32 | * The constructor. |
||
33 | * |
||
34 | * @param mixed $path |
||
35 | * @param \Illuminate\Filesystem\Filesystem $filesystem |
||
36 | */ |
||
37 | 88 | public function __construct($path, Filesystem $filesystem = null) |
|
43 | |||
44 | /** |
||
45 | * Get filesystem. |
||
46 | * |
||
47 | * @return Filesystem |
||
48 | */ |
||
49 | 2 | public function getFilesystem() |
|
53 | |||
54 | /** |
||
55 | * Set filesystem. |
||
56 | * |
||
57 | * @param Filesystem $filesystem |
||
58 | * |
||
59 | * @return $this |
||
60 | */ |
||
61 | public function setFilesystem(Filesystem $filesystem) |
||
67 | |||
68 | /** |
||
69 | * Get path. |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | 88 | public function getPath() |
|
77 | |||
78 | /** |
||
79 | * Set path. |
||
80 | * |
||
81 | * @param mixed $path |
||
82 | * |
||
83 | * @return $this |
||
84 | */ |
||
85 | 1 | public function setPath($path) |
|
91 | |||
92 | /** |
||
93 | * Make new instance. |
||
94 | * |
||
95 | * @param string $path |
||
96 | * @param \Illuminate\Filesystem\Filesystem $filesystem |
||
97 | * |
||
98 | * @return static |
||
99 | */ |
||
100 | 70 | public static function make($path, Filesystem $filesystem = null) |
|
104 | |||
105 | /** |
||
106 | * Get file content. |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | 88 | public function getContents() |
|
114 | |||
115 | /** |
||
116 | * Get file contents as array. |
||
117 | * @return array |
||
118 | * @throws \Exception |
||
119 | */ |
||
120 | 88 | public function getAttributes() |
|
137 | |||
138 | /** |
||
139 | * Convert the given array data to pretty json. |
||
140 | * |
||
141 | * @param array $data |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | 5 | public function toJsonPretty(array $data = null) |
|
149 | |||
150 | /** |
||
151 | * Update json contents from array data. |
||
152 | * |
||
153 | * @param array $data |
||
154 | * |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function update(array $data) |
||
163 | |||
164 | /** |
||
165 | * Set a specific key & value. |
||
166 | * |
||
167 | * @param string $key |
||
168 | * @param mixed $value |
||
169 | * |
||
170 | * @return $this |
||
171 | */ |
||
172 | 5 | public function set($key, $value) |
|
178 | |||
179 | /** |
||
180 | * Save the current attributes array to the file storage. |
||
181 | * |
||
182 | * @return bool |
||
183 | */ |
||
184 | 4 | public function save() |
|
188 | |||
189 | /** |
||
190 | * Handle magic method __get. |
||
191 | * |
||
192 | * @param string $key |
||
193 | * |
||
194 | * @return mixed |
||
195 | */ |
||
196 | 1 | public function __get($key) |
|
200 | |||
201 | /** |
||
202 | * Get the specified attribute from json file. |
||
203 | * |
||
204 | * @param $key |
||
205 | * @param null $default |
||
206 | * |
||
207 | * @return mixed |
||
208 | */ |
||
209 | 80 | public function get($key, $default = null) |
|
213 | |||
214 | /** |
||
215 | * Handle call to __call method. |
||
216 | * |
||
217 | * @param string $method |
||
218 | * @param array $arguments |
||
219 | * |
||
220 | * @return mixed |
||
221 | */ |
||
222 | public function __call($method, $arguments = []) |
||
230 | |||
231 | /** |
||
232 | * Handle call to __toString method. |
||
233 | * |
||
234 | * @return string |
||
235 | */ |
||
236 | 1 | public function __toString() |
|
240 | } |
||
241 |