Example #1
0
 protected function parse_args(array $args)
 {
     if (count($args) < 1) {
         throw new \InvalidArgumentException("Usage: script/generate plugin plugin_id [plugin_title]");
     }
     $this->plugin_id = array_shift($args);
     $this->plugin_class = str_replace('-', '_', \Inflector::camelize(str_replace('.', '_', $this->plugin_id)));
     $this->plugin_title = count($args) ? array_shift($args) : $this->plugin_id;
     $this->plugin_dir = 'plugins/' . $this->plugin_id;
     if (!\zing\plugin\Utils::is_valid_plugin_id($this->plugin_id)) {
         throw new \InvalidArgumentException("'{$this->plugin_id}' is not a valid plugin ID");
     }
     $manager = \zing\plugin\Manager::instance();
     if ($manager->is_plugin_installed($this->plugin_id)) {
         throw new \InvalidArgumentException("'{$this->plugin_id}' is already installed");
     }
 }
Example #2
0
 private function find_plugin_dir()
 {
     $stack = array($this->tmp_dir);
     while (count($stack)) {
         $dir = array_pop($stack);
         if (\zing\plugin\Utils::is_plugin($dir)) {
             $this->plugin_dir = $dir;
             $this->reporter->success("Plugin directory located");
             return;
         } else {
             $candidates = glob($dir . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR);
             foreach ($candidates as $c) {
                 $stack[] = $c;
             }
         }
     }
     throw new \Exception("couldn't find a valid plugin directory, giving up.\n");
 }