/**
  * list all modules commands
  * @param $args
  * @param $assoc_args
  */
 public function all_cmds($args, $assoc_args)
 {
     HW_HOANGWEB::load_class('HW_Ajax');
     $Utilities = HW_CLI_Command_Utilities::get_instance();
     HW_Ajax::result($Utilities->get_clis());
 }
 /**
  * copy from modules/command.php
  * @param $subcommand
  * @param string|array $param_id get first params for default
  * @param $command if not specific get module name as command name
  * @return string
  */
 public function get_cli_cmd($subcommand, $param_id = 0, $command_name = '')
 {
     $module = $this->get_current_module();
     if ((empty($command_name) || !$module->exist_command($command_name)) && !HW_CLI_Command_Utilities::is_sys_cmd($command_name)) {
         $command_name = $module->option('module_name');
     }
     $wp_cli = HW_HOANGWEB_PATH . 'lib/wp.phar';
     //wp cli phar
     $home_url = home_url();
     $home_path = get_home_path();
     //prepare arguments
     if (is_array($param_id)) {
         $args = HW_CLI_Command_Utilities::parse_cmd_args($param_id);
     } elseif (is_string($param_id) || is_numeric($param_id)) {
         $args = "--___config_id={$param_id}";
     } else {
         $args = '';
     }
     //$cmd ="@echo Off&&";
     //$cmd .= "SET PATH=%PATH%;E:/HoangData/xampp_htdocs/wp.phar&&";
     $cmd = "php {$wp_cli} {$command_name} {$subcommand} {$args} --url={$home_url} --path={$home_path}";
     #$cmd .= "timeout /t 50";    //pause for 50s
     return $cmd;
 }
 /**
  * main class constructor
  */
 public function __construct()
 {
     //get current module from cli command
     $this->get_current_module();
     $this->get_config();
     //config module
     $this->cli = HW_CLI_Command_Utilities::get_instance();
 }
 /**
  * init module
  */
 public static final function init()
 {
     $class = get_called_class();
     if ($class) {
         $inst = new $class();
         if (!$inst instanceof HW_Module) {
             return;
         }
         //get file name where a Class was Defined
         $reflector = new ReflectionClass($class);
         //path variables
         $inst->option('module_path', dirname($reflector->getFileName()));
         $module_slug = basename($inst->option('module_path'));
         $inst->option('module_name', $module_slug);
         $modules = HW_TGM_Module_Activation::get_register_modules();
         if (isset($modules[$module_slug])) {
             $info = array_filter(HW_Plugins_Manager::get_module_info($reflector->getFileName()));
             //migrate module information
             if (!empty($info)) {
                 $modules[$module_slug] = array_merge($modules[$module_slug], $info);
             }
             HW_Plugins_Manager::register_module($modules[$module_slug]);
             //update module data
             $inst->option('module_info', $modules[$module_slug]);
         }
         $inst->option('module_url', HW_HOANGWEB_PLUGINS_URL . '/' . $module_slug);
         HW_Module_Settings_page::add_module($module_slug, $inst);
         //setup actions belong to current module instance
         self::setup_actions($inst);
         //occur after all modules loaded
         add_action('hw_modules_loaded', array($inst, 'modules_loaded'));
         //after the module loaded
         if (method_exists($inst, 'module_loaded')) {
             $inst->module_loaded();
         }
         //load cli class for the module
         $command = $inst->get_module_cli_path();
         if (!empty($command) && defined('WP_CLI') && WP_CLI) {
             include_once $command;
             $cli_class = 'HW_CLI_' . HW_Validation::valid_objname($module_slug);
             //command line class
             WP_CLI::add_command($module_slug, strtoupper($cli_class));
             //WP_CLI::get_command(); #wrong
             //add module commands to manager
             HW_CLI_Command_Utilities::get_instance()->register_cli_cmds($module_slug, HW_Core::get_child_class_methods($cli_class, ReflectionMethod::IS_PUBLIC));
         }
         //load oher cli class for module
         $cli_files = $inst->get_commands();
         if (is_array($cli_files)) {
             foreach ($cli_files as $cli) {
                 //not found file to process command line,
                 if (!$cli) {
                     continue;
                 }
                 //!isset($cli['file']) purpose for module->register_cli that more cli class write in one file
                 if (isset($cli['file'])) {
                     include_once $cli['file'];
                 }
                 if (class_exists($cli['class'], false)) {
                     WP_CLI::add_command($cli['command'], $cli['class']);
                     //add module commands to manager
                     HW_CLI_Command_Utilities::get_instance()->register_cli_cmds($cli['command'], HW_Core::get_child_class_methods($cli['class'], ReflectionMethod::IS_PUBLIC));
                 }
             }
         }
     }
 }