@@ -201,33 +201,15 @@ private static function _add($module, $path) {
201201 *
202202 * @since 1.0.0
203203 *
204- * @throws ModuleException → file not found
205- *
206204 * @return array → modules states
207205 */
208206 public static function getStates () {
209207
210208 if (is_null (self ::$ states )) {
211209
212- $ path = App::ROOT () . 'modules ' . App::DS ;
213-
214- $ filepath = $ path . App::modules ('states-file ' );
215-
216- if (is_file ($ filepath )) {
217-
218- $ file = file_get_contents ($ filepath );
219-
220- return self ::$ states = json_decode ($ file , true );
221-
222- } else {
223-
224- return self ::_setStates ();
225-
226- }
227-
228- $ message = 'modules-states.jsond file not found in ' ;
210+ $ filepath = App::MODULES () . App::modules ('states-file ' );
229211
230- throw new ModuleException ( $ message . ' ' . $ path , 605 );
212+ self :: $ states = Json:: fileToArray ( $ filepath );
231213 }
232214
233215 return self ::$ states ;
@@ -237,25 +219,12 @@ public static function getStates() {
237219 * Save states for modules.
238220 *
239221 * @since 1.0.0
240- *
241- * @throws ModuleException → file could not be created
242222 */
243223 private static function _setStates () {
244224
245- $ path = App::ROOT () . 'modules ' . App::DS ;
246-
247- $ filepath = $ path . App::modules ('states-file ' );
248-
249- $ json = json_encode (self ::$ states , JSON_PRETTY_PRINT );
250-
251- if (!$ file = fopen ($ filepath , 'w+ ' )) {
252-
253- $ message = 'modules-states.jsond could not be created in ' ;
254-
255- throw new ModuleException ($ message . ' ' . $ filepath , 300 );
256- }
225+ $ filepath = App::MODULES () . App::modules ('states-file ' );
257226
258- fwrite ( $ file , $ json );
227+ Json:: ArrayToFile ( self :: $ states , $ filepath );
259228 }
260229
261230 /**
@@ -324,6 +293,45 @@ private function _setAction($action) {
324293 self ::$ states [App::$ id ][self ::$ id ]['action ' ] = $ action ;
325294 }
326295
296+ /**
297+ * Delete module.
298+ *
299+ * @since 1.0.0
300+ *
301+ * @param boolean $moduleName → plugin name to delete
302+ * @param boolean $deleteAll → delete the entire directory or
303+ * leave only the configuration file.
304+ *
305+ * @return string → module state
306+ */
307+ public static function remove ($ moduleName = null , $ deleteAll = true ) {
308+
309+ $ instance = self ::getInstance ();
310+
311+ self ::$ id = ($ moduleName ) ? $ moduleName : self ::$ id ;
312+
313+ if (isset ($ instance ->modules [App::$ id ][self ::$ id ]['path ' ]['root ' ])) {
314+
315+ $ instance ->_setState ('remove ' );
316+
317+ $ instance ->changeState ();
318+
319+ $ path = $ instance ->modules [App::$ id ][self ::$ id ]['path ' ]['root ' ];
320+
321+ //$instance->_deleteDir($path, $deleteAll);
322+
323+ if ($ deleteAll ) {
324+
325+ unset($ this ->modules [App::$ id ][self ::$ id ]);
326+ unset(self ::$ states [App::$ id ][self ::$ id ]);
327+ }
328+
329+ self ::_setStates ();
330+ }
331+
332+ return 'uninstalled ' ;
333+ }
334+
327335 /**
328336 * Change module state.
329337 *
@@ -378,45 +386,6 @@ public static function changeState($moduleName = null) {
378386 return $ state ;
379387 }
380388
381- /**
382- * Delete module.
383- *
384- * @since 1.0.0
385- *
386- * @param boolean $moduleName → plugin name to delete
387- * @param boolean $deleteAll → delete the entire directory or
388- * leave only the configuration file.
389- *
390- * @return string → module state
391- */
392- public static function remove ($ moduleName = null , $ deleteAll = true ) {
393-
394- $ instance = self ::getInstance ();
395-
396- self ::$ id = ($ moduleName ) ? $ moduleName : self ::$ id ;
397-
398- if (isset ($ instance ->modules [App::$ id ][self ::$ id ]['path ' ]['root ' ])) {
399-
400- $ instance ->_setState ('remove ' );
401-
402- $ instance ->changeState ();
403-
404- $ path = $ instance ->modules [App::$ id ][self ::$ id ]['path ' ]['root ' ];
405-
406- //$instance->_deleteDir($path, $deleteAll);
407-
408- if ($ deleteAll ) {
409-
410- unset($ this ->modules [App::$ id ][self ::$ id ]);
411- unset(self ::$ states [App::$ id ][self ::$ id ]);
412- }
413-
414- self ::_setStates ();
415- }
416-
417- return 'uninstalled ' ;
418- }
419-
420389 /**
421390 * Delete module.
422391 *
@@ -486,9 +455,11 @@ private function _deleteDir($modulePath, $deleteAll) {
486455 *
487456 * @since 1.0.0
488457 *
458+ * @param string $category → module category
459+ *
489460 * @return array $data → modules info
490461 */
491- public static function getModulesInfo () {
462+ public static function getModulesInfo ($ category = ' all ' ) {
492463
493464 $ data = [];
494465
@@ -500,6 +471,11 @@ public static function getModulesInfo() {
500471
501472 $ module = $ instance ->modules [App::$ id ][$ module ];
502473
474+ if ($ category !== 'all ' && $ module ['category ' ] !== $ category ) {
475+
476+ continue ;
477+ }
478+
503479 $ data [] = [
504480
505481 'id ' => $ module ['id ' ],
@@ -576,6 +552,22 @@ private function _addResources() {
576552 }
577553 }
578554 }
555+
556+ /**
557+ * Check if module exists.
558+ *
559+ * @since 1.0.2
560+ *
561+ * @param string $id → module id
562+ *
563+ * @return boolean
564+ */
565+ public static function exists ($ id ) {
566+
567+ $ instance = self ::getInstance ();
568+
569+ return array_key_exists ($ id , $ instance ->modules [App::$ id ]);
570+ }
579571
580572 /**
581573 * Receives the name of the module to execute: Module::ModuleName();
@@ -603,10 +595,11 @@ public static function __callstatic($index, $params = '') {
603595 self ::$ id = $ index ;
604596
605597 $ method = (isset ($ params [0 ])) ? $ params [0 ] : '' ;
598+ $ args = (isset ($ params [1 ])) ? $ params [1 ] : [];
606599
607600 if (method_exists ($ instance , $ method )) {
608601
609- call_user_func ([$ instance , $ method ]);
602+ return call_user_func_array ([$ instance , $ method ], $ args );
610603 }
611604
612605 $ column [] = $ instance ->modules [App::$ id ][$ index ];
0 commit comments