public static function run_command() { $command = static::$command; $method = static::$method; // Let's see if the command file exists. $path = SYS . 'cli/commands/' . $command . '.' . EXT; if (!File::exists($path, false)) { throw new CLIException('Unable to load file.'); } // Let's include the file. require_once $path; // Let's check if the class exists. $_command = "CLI\\Command\\" . ucfirst($command); if (!class_exists($_command)) { throw new CLIException('Class ' . $_command . ' doesn\'t exists.'); } // Let's create a new instance of the command object. $task = new $_command(); // Let's check if the method is callable. if (!is_callable(array($task, $method))) { throw new CLIException('Unable to call ' . $method . ' in ' . $command); } // Let's call the method and by that finally run the command. $output = $task->{$method}(static::$arguments, static::$options); // If there was a returned value print it. if (!empty($output)) { echo $output . PHP_EOL; } }
public static function reg_pkg($pkg) { try { File::exists($pkg . '/required.json'); } catch (Exception $e) { die($e->getMessage()); } $required = json_decode(File::get($pkg . '/required.json', true)); foreach ($required as $file) { static::register($pkg . '/' . $file); } }
/** * Generates a view. */ public function view($arg, $opt) { if (!isset($arg[0])) { throw new CLIException('To generate a model, you must provide a name.'); } $override = false; if (array_search('--override', $opt) !== false) { $override = true; } $this->template = 'templates/gen_view.txt'; $this->path = APP . 'view/' . $arg[0] . '.' . EXT; if (File::exists($this->path, false) === true && $override === false) { // If the view file already exists, warn the user. // If, however, the user wants to override, tell the user // to add the flag "--override" to the command. throw new CLIException('View file already exists. Add the flag "--override" to allow overriding files.'); } $this->replacements = array(); return $this->makeFile($this->template, $this->path); }