Ejemplo n.º 1
0
 /**
  * register cli command
  * @param $file
  * @param $command
  * @param $class
  */
 public function register_cli($file, $command = '', $class = '')
 {
     static $commands = array();
     if ($file && !file_exists($file)) {
         $name = rtrim($file, '.php');
         //remove extension
         if (!$command || is_numeric($command)) {
             $command = $name;
         }
         $file = trim(HW_File_Directory::generate_path($this->option('module_path'), 'cli/class-cli-' . $name . '.php'), '\\/');
     } elseif (!is_dir($file) && file_exists($file) && preg_match('#class-cli-*#', basename($file))) {
         $fname = HW_File_Directory::split_filename($file);
         if (!$command) {
             $command = str_replace('class-cli-', '', $fname);
         }
         //extract command name base file name
     }
     if (!is_dir($file) && file_exists($file) && $command && !isset($commands[$command])) {
         //make sure commands is not same
         if (!$class) {
             $class = 'HW_CLI_HW_' . ucwords(HW_Validation::valid_objname($command));
         }
         //desire command class name
         $this->option('cli_files', array($command => array('command' => $command, 'path' => $file, 'class' => $class)), true);
         $commands[$command] = 1;
     }
 }