1 | <?php |
||
7 | class Json |
||
8 | { |
||
9 | /** |
||
10 | * The file path. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $path; |
||
15 | |||
16 | /** |
||
17 | * The laravel filesystem instance. |
||
18 | * |
||
19 | * @var \Illuminate\Filesystem\Filesystem |
||
20 | */ |
||
21 | protected $filesystem; |
||
22 | |||
23 | /** |
||
24 | * The attributes collection. |
||
25 | * |
||
26 | * @var \Illuminate\Support\Collection |
||
27 | */ |
||
28 | protected $attributes; |
||
29 | |||
30 | /** |
||
31 | * The constructor. |
||
32 | * |
||
33 | * @param mixed $path |
||
34 | * @param \Illuminate\Filesystem\Filesystem $filesystem |
||
35 | */ |
||
36 | 39 | public function __construct($path, Filesystem $filesystem = null) |
|
42 | |||
43 | /** |
||
44 | * Get filesystem. |
||
45 | * |
||
46 | * @return Filesystem |
||
47 | */ |
||
48 | public function getFilesystem() |
||
52 | |||
53 | /** |
||
54 | * Set filesystem. |
||
55 | * |
||
56 | * @param Filesystem $filesystem |
||
57 | * |
||
58 | * @return $this |
||
59 | */ |
||
60 | public function setFilesystem(Filesystem $filesystem) |
||
66 | |||
67 | /** |
||
68 | * Get path. |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | 39 | public function getPath() |
|
76 | |||
77 | /** |
||
78 | * Set path. |
||
79 | * |
||
80 | * @param mixed $path |
||
81 | * |
||
82 | * @return $this |
||
83 | */ |
||
84 | 1 | public function setPath($path) |
|
90 | |||
91 | /** |
||
92 | * Make new instance. |
||
93 | * |
||
94 | * @param string $path |
||
95 | * @param \Illuminate\Filesystem\Filesystem $filesystem |
||
96 | * |
||
97 | * @return static |
||
98 | */ |
||
99 | 25 | public static function make($path, Filesystem $filesystem = null) |
|
103 | |||
104 | /** |
||
105 | * Get file content. |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | 39 | public function getContents() |
|
113 | |||
114 | /** |
||
115 | * Get file contents as array. |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | 39 | public function getAttributes() |
|
129 | |||
130 | /** |
||
131 | * Convert the given array data to pretty json. |
||
132 | * |
||
133 | * @param array $data |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | 1 | public function toJsonPretty(array $data = null) |
|
141 | |||
142 | /** |
||
143 | * Update json contents from array data. |
||
144 | * |
||
145 | * @param array $data |
||
146 | * |
||
147 | * @return bool |
||
148 | */ |
||
149 | public function update(array $data) |
||
155 | |||
156 | /** |
||
157 | * Set a specific key & value. |
||
158 | * |
||
159 | * @param string $key |
||
160 | * @param mixed $value |
||
161 | * |
||
162 | * @return $this |
||
163 | */ |
||
164 | 1 | public function set($key, $value) |
|
170 | |||
171 | /** |
||
172 | * Save the current attributes array to the file storage. |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function save() |
||
180 | |||
181 | /** |
||
182 | * Handle magic method __get. |
||
183 | * |
||
184 | * @param string $key |
||
185 | * |
||
186 | * @return mixed |
||
187 | */ |
||
188 | 1 | public function __get($key) |
|
192 | |||
193 | /** |
||
194 | * Get the specified attribute from json file. |
||
195 | * |
||
196 | * @param $key |
||
197 | * @param null $default |
||
198 | * |
||
199 | * @return mixed |
||
200 | */ |
||
201 | 34 | public function get($key, $default = null) |
|
205 | |||
206 | /** |
||
207 | * Handle call to __call method. |
||
208 | * |
||
209 | * @param string $method |
||
210 | * @param array $arguments |
||
211 | * |
||
212 | * @return mixed |
||
213 | */ |
||
214 | public function __call($method, $arguments = []) |
||
222 | |||
223 | /** |
||
224 | * Handle call to __toString method. |
||
225 | * |
||
226 | * @return string |
||
227 | */ |
||
228 | 1 | public function __toString() |
|
232 | } |
||
233 |