1 | <?php |
||
10 | abstract class Module extends ServiceProvider |
||
11 | { |
||
12 | use Macroable; |
||
13 | |||
14 | /** |
||
15 | * The laravel|lumen application instance. |
||
16 | * |
||
17 | * @var \Illuminate\Contracts\Foundation\Application|Laravel\Lumen\Application |
||
18 | */ |
||
19 | protected $app; |
||
20 | |||
21 | /** |
||
22 | * The module name. |
||
23 | * |
||
24 | * @var |
||
25 | */ |
||
26 | protected $name; |
||
27 | |||
28 | /** |
||
29 | * The module path. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $path; |
||
34 | |||
35 | /** |
||
36 | * @var array of cached Json objects, keyed by filename |
||
37 | */ |
||
38 | protected $moduleJson = []; |
||
39 | |||
40 | /** |
||
41 | * The constructor. |
||
42 | * |
||
43 | * @param Container $app |
||
44 | * @param $name |
||
45 | * @param $path |
||
46 | */ |
||
47 | 142 | public function __construct(Container $app, $name, $path) |
|
53 | |||
54 | /** |
||
55 | * Get laravel instance. |
||
56 | * |
||
57 | * @return \Illuminate\Contracts\Foundation\Application|Laravel\Lumen\Application |
||
58 | */ |
||
59 | 1 | public function getLaravel() |
|
63 | |||
64 | /** |
||
65 | * Get name. |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | 2 | public function getName() |
|
73 | |||
74 | /** |
||
75 | * Get name in lower case. |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | 107 | public function getLowerName() |
|
83 | |||
84 | /** |
||
85 | * Get name in studly case. |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | 93 | public function getStudlyName() |
|
93 | |||
94 | /** |
||
95 | * Get name in snake case. |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | 6 | public function getSnakeName() |
|
103 | |||
104 | /** |
||
105 | * Get description. |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | 2 | public function getDescription() |
|
113 | |||
114 | /** |
||
115 | * Get alias. |
||
116 | * |
||
117 | * @return string |
||
118 | */ |
||
119 | 4 | public function getAlias() |
|
123 | |||
124 | /** |
||
125 | * Get priority. |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | public function getPriority() |
||
133 | |||
134 | /** |
||
135 | * Get module requirements. |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | 3 | public function getRequires() |
|
143 | |||
144 | /** |
||
145 | * Get path. |
||
146 | * |
||
147 | * @return string |
||
148 | */ |
||
149 | 126 | public function getPath() |
|
153 | |||
154 | /** |
||
155 | * Set path. |
||
156 | * |
||
157 | * @param string $path |
||
158 | * |
||
159 | * @return $this |
||
160 | */ |
||
161 | public function setPath($path) |
||
167 | |||
168 | /** |
||
169 | * Bootstrap the application events. |
||
170 | */ |
||
171 | 2 | public function boot() |
|
172 | { |
||
173 | 2 | if (config('modules.register.translations', true) === true) { |
|
174 | 2 | $this->registerTranslation(); |
|
175 | } |
||
176 | |||
177 | 2 | $this->registerFiles(); |
|
178 | |||
179 | 2 | $this->fireEvent('boot'); |
|
180 | 2 | } |
|
181 | |||
182 | /** |
||
183 | * Register module's translation. |
||
184 | * |
||
185 | * @return void |
||
186 | */ |
||
187 | 2 | protected function registerTranslation() |
|
188 | { |
||
189 | 2 | $lowerName = $this->getLowerName(); |
|
190 | |||
191 | 2 | $langPath = $this->getPath() . '/Resources/lang'; |
|
192 | |||
193 | 2 | if (is_dir($langPath)) { |
|
194 | 2 | $this->loadTranslationsFrom($langPath, $lowerName); |
|
195 | } |
||
196 | 2 | } |
|
197 | |||
198 | /** |
||
199 | * Get json contents from the cache, setting as needed. |
||
200 | * |
||
201 | * @param string $file |
||
202 | * |
||
203 | * @return Json |
||
204 | */ |
||
205 | 36 | public function json($file = null) : Json |
|
206 | { |
||
207 | 36 | if ($file === null) { |
|
208 | 34 | $file = 'module.json'; |
|
209 | } |
||
210 | |||
211 | 36 | return array_get($this->moduleJson, $file, function () use ($file) { |
|
212 | 36 | return $this->moduleJson[$file] = new Json($this->getPath() . '/' . $file, $this->app['files']); |
|
213 | 36 | }); |
|
214 | } |
||
215 | |||
216 | /** |
||
217 | * Get a specific data from json file by given the key. |
||
218 | * |
||
219 | * @param string $key |
||
220 | * @param null $default |
||
221 | * |
||
222 | * @return mixed |
||
223 | */ |
||
224 | 26 | public function get(string $key, $default = null) |
|
225 | { |
||
226 | 26 | return $this->json()->get($key, $default); |
|
227 | } |
||
228 | |||
229 | /** |
||
230 | * Get a specific data from composer.json file by given the key. |
||
231 | * |
||
232 | * @param $key |
||
233 | * @param null $default |
||
234 | * |
||
235 | * @return mixed |
||
236 | */ |
||
237 | 2 | public function getComposerAttr($key, $default = null) |
|
238 | { |
||
239 | 2 | return $this->json('composer.json')->get($key, $default); |
|
240 | } |
||
241 | |||
242 | /** |
||
243 | * Register the module. |
||
244 | */ |
||
245 | public function register() |
||
246 | { |
||
247 | $this->registerAliases(); |
||
248 | |||
249 | $this->registerProviders(); |
||
250 | |||
251 | $this->fireEvent('register'); |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * Register the module event. |
||
256 | * |
||
257 | * @param string $event |
||
258 | */ |
||
259 | 8 | protected function fireEvent($event) |
|
263 | /** |
||
264 | * Register the aliases from this module. |
||
265 | */ |
||
266 | abstract public function registerAliases(); |
||
267 | |||
268 | /** |
||
269 | * Register the service providers from this module. |
||
270 | */ |
||
271 | abstract public function registerProviders(); |
||
272 | |||
273 | /** |
||
274 | * Get the path to the cached *_module.php file. |
||
275 | * |
||
276 | * @return string |
||
277 | */ |
||
278 | abstract public function getCachedServicesPath(); |
||
279 | |||
280 | /** |
||
281 | * Register the files from this module. |
||
282 | */ |
||
283 | 2 | protected function registerFiles() |
|
284 | { |
||
285 | 2 | foreach ($this->get('files', []) as $file) { |
|
286 | include $this->path . '/' . $file; |
||
287 | } |
||
288 | 2 | } |
|
289 | |||
290 | /** |
||
291 | * Handle call __toString. |
||
292 | * |
||
293 | * @return string |
||
294 | */ |
||
295 | 3 | public function __toString() |
|
299 | |||
300 | /** |
||
301 | * Determine whether the given status same with the current module status. |
||
302 | * |
||
303 | * @param $status |
||
304 | * |
||
305 | * @return bool |
||
306 | */ |
||
307 | 11 | public function isStatus($status) : bool |
|
311 | |||
312 | /** |
||
313 | * Determine whether the current module activated. |
||
314 | * |
||
315 | * @return bool |
||
316 | */ |
||
317 | 2 | public function enabled() : bool |
|
321 | |||
322 | /** |
||
323 | * Alternate for "enabled" method. |
||
324 | * |
||
325 | * @return bool |
||
326 | * @deprecated |
||
327 | */ |
||
328 | 6 | public function active() |
|
332 | |||
333 | /** |
||
334 | * Determine whether the current module not activated. |
||
335 | * |
||
336 | * @return bool |
||
337 | * @deprecated |
||
338 | */ |
||
339 | 2 | public function notActive() |
|
343 | |||
344 | /** |
||
345 | * Determine whether the current module not disabled. |
||
346 | * |
||
347 | * @return bool |
||
348 | */ |
||
349 | 2 | public function disabled() : bool |
|
353 | |||
354 | /** |
||
355 | * Set active state for current module. |
||
356 | * |
||
357 | * @param $active |
||
358 | * |
||
359 | * @return bool |
||
360 | */ |
||
361 | 6 | public function setActive($active) |
|
365 | |||
366 | /** |
||
367 | * Disable the current module. |
||
368 | */ |
||
369 | 3 | public function disable() |
|
377 | |||
378 | /** |
||
379 | * Enable the current module. |
||
380 | */ |
||
381 | 3 | public function enable() |
|
389 | |||
390 | /** |
||
391 | * Delete the current module. |
||
392 | * |
||
393 | * @return bool |
||
394 | */ |
||
395 | 2 | public function delete() |
|
399 | |||
400 | /** |
||
401 | * Get extra path. |
||
402 | * |
||
403 | * @param string $path |
||
404 | * |
||
405 | * @return string |
||
406 | */ |
||
407 | 3 | public function getExtraPath(string $path) : string |
|
411 | |||
412 | /** |
||
413 | * Handle call to __get method. |
||
414 | * |
||
415 | * @param $key |
||
416 | * |
||
417 | * @return mixed |
||
418 | */ |
||
419 | public function __get($key) |
||
423 | } |
||
424 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: