1 | <?php |
||
5 | class LocalRepository extends Repository |
||
6 | { |
||
7 | /** |
||
8 | * Update cached repository of module information. |
||
9 | * |
||
10 | * @return bool |
||
11 | */ |
||
12 | public function optimize() |
||
13 | { |
||
14 | $cachePath = $this->getCachePath(); |
||
15 | $cache = $this->getCache(); |
||
16 | $basenames = $this->getAllBasenames(); |
||
17 | $modules = collect(); |
||
18 | |||
19 | $basenames->each(function ($module, $key) use ($modules, $cache) { |
||
|
|||
20 | $temp = collect($cache->get($module)); |
||
21 | $manifest = collect($this->getManifest($module)); |
||
22 | |||
23 | $modules->put($module, $temp->merge($manifest)); |
||
24 | }); |
||
25 | |||
26 | $modules->each(function ($module) { |
||
27 | if (!$module->has('enabled')) { |
||
28 | $module->put('enabled', config('modules.enabled', true)); |
||
29 | } |
||
30 | |||
31 | if (!$module->has('order')) { |
||
32 | $module->put('order', 9001); |
||
33 | } |
||
34 | |||
35 | return $module; |
||
36 | }); |
||
37 | |||
38 | $content = json_encode($modules->all(), JSON_PRETTY_PRINT); |
||
39 | |||
40 | return $this->files->put($cachePath, $content); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Get all modules. |
||
45 | * |
||
46 | * @return Collection |
||
47 | */ |
||
48 | public function all() |
||
52 | |||
53 | /** |
||
54 | * Get all module slugs. |
||
55 | * |
||
56 | * @return Collection |
||
57 | */ |
||
58 | public function slugs() |
||
68 | |||
69 | /** |
||
70 | * Get modules based on where clause. |
||
71 | * |
||
72 | * @param string $key |
||
73 | * @param mixed $value |
||
74 | * |
||
75 | * @return Collection |
||
76 | */ |
||
77 | public function where($key, $value) |
||
81 | |||
82 | /** |
||
83 | * Sort modules by given key in ascending order. |
||
84 | * |
||
85 | * @param string $key |
||
86 | * |
||
87 | * @return Collection |
||
88 | */ |
||
89 | public function sortBy($key) |
||
95 | |||
96 | /** |
||
97 | * Sort modules by given key in ascending order. |
||
98 | * |
||
99 | * @param string $key |
||
100 | * |
||
101 | * @return Collection |
||
102 | */ |
||
103 | public function sortByDesc($key) |
||
109 | |||
110 | /** |
||
111 | * Determines if the given module exists. |
||
112 | * |
||
113 | * @param string $slug |
||
114 | * |
||
115 | * @return bool |
||
116 | */ |
||
117 | public function exists($slug) |
||
121 | |||
122 | /** |
||
123 | * Returns count of all modules. |
||
124 | * |
||
125 | * @return int |
||
126 | */ |
||
127 | public function count() |
||
131 | |||
132 | /** |
||
133 | * Get a module property value. |
||
134 | * |
||
135 | * @param string $property |
||
136 | * @param mixed $default |
||
137 | * |
||
138 | * @return mixed |
||
139 | */ |
||
140 | public function get($property, $default = null) |
||
148 | |||
149 | /** |
||
150 | * Set the given module property value. |
||
151 | * |
||
152 | * @param string $property |
||
153 | * @param mixed $value |
||
154 | * |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function set($property, $value) |
||
158 | { |
||
159 | list($slug, $key) = explode('::', $property); |
||
160 | |||
161 | $cachePath = $this->getCachePath(); |
||
162 | $cache = $this->getCache(); |
||
163 | $module = $this->where('slug', $slug); |
||
164 | $moduleKey = $module->keys()->first(); |
||
165 | $values = $module->first(); |
||
166 | |||
167 | if (isset($values[$key])) { |
||
168 | unset($values[$key]); |
||
169 | } |
||
170 | |||
171 | $values[$key] = $value; |
||
172 | |||
173 | $module = collect([$moduleKey => $values]); |
||
174 | |||
175 | $merged = $cache->merge($module); |
||
176 | $content = json_encode($merged->all(), JSON_PRETTY_PRINT); |
||
177 | |||
178 | return $this->files->put($cachePath, $content); |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Get all enabled modules. |
||
183 | * |
||
184 | * @return Collection |
||
185 | */ |
||
186 | public function enabled() |
||
190 | |||
191 | /** |
||
192 | * Get all disabled modules. |
||
193 | * |
||
194 | * @return Collection |
||
195 | */ |
||
196 | public function disabled() |
||
200 | |||
201 | /** |
||
202 | * Check if specified module is enabled. |
||
203 | * |
||
204 | * @param string $slug |
||
205 | * |
||
206 | * @return bool |
||
207 | */ |
||
208 | public function isEnabled($slug) |
||
215 | |||
216 | /** |
||
217 | * Check if specified module is disabled. |
||
218 | * |
||
219 | * @param string $slug |
||
220 | * |
||
221 | * @return bool |
||
222 | */ |
||
223 | public function isDisabled($slug) |
||
230 | |||
231 | /** |
||
232 | * Enables the specified module. |
||
233 | * |
||
234 | * @param string $slug |
||
235 | * |
||
236 | * @return bool |
||
237 | */ |
||
238 | public function enable($slug) |
||
242 | |||
243 | /** |
||
244 | * Disables the specified module. |
||
245 | * |
||
246 | * @param string $slug |
||
247 | * |
||
248 | * @return bool |
||
249 | */ |
||
250 | public function disable($slug) |
||
254 | |||
255 | /** |
||
256 | * Get the contents of the cache file. |
||
257 | * |
||
258 | * The cache file lists all module slugs and their |
||
259 | * enabled or disabled status. This can be used to |
||
260 | * filter out modules depending on their status. |
||
261 | * |
||
262 | * @return Collection |
||
263 | */ |
||
264 | public function getCache() |
||
280 | |||
281 | /** |
||
282 | * Get the path to the cache file. |
||
283 | * |
||
284 | * @return string |
||
285 | */ |
||
286 | protected function getCachePath() |
||
290 | } |
||
291 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.