Exemplo n.º 1
0
 /**
  * generate ships
  *
  * exmample:
  * run shipyard::ship <name>
  * run shipyard::ship <name> <namespace>
  * run shipyard::ship <name> --no-namespace
  *
  * @param array 		$params 
  * @return void
  */
 public function action_ship($params)
 {
     $options = \CCDataObject::assign($params);
     $name = $options->get(0, null);
     $namespace = $options->get(1, null);
     // get name if we dont have one
     while (!$name) {
         $name = CCCli::read('Please enter the ship name: ');
     }
     // set namespace
     if (!$namespace) {
         $namespace = $name;
     }
     // no namespace?
     if ($params['no-namespace']) {
         $namespace = false;
     }
     // custom target
     $target = $options->get('target', ORBITPATH);
     if (substr($target, 0, 1) !== '/') {
         $target = CCFPATH . $target;
     }
     if (substr($target, -1) !== '/') {
         $target .= '/';
     }
     $target .= $name . '/';
     // check if the module is in our orbit path
     if (is_dir($target)) {
         if (!CCCli::confirm("there is already a ship with this name. do you want to overwrite?", true)) {
             return;
         }
     }
     // create the blueprint
     $defaults = \CCConfig::create('shipyard');
     $blueprint = array('name' => $name, 'version' => $defaults->get('defaults.version'), 'description' => $defaults->get('defaults.description'), 'homepage' => $defaults->get('defaults.homepage'), 'keywords' => $defaults->get('defaults.keywords'), 'license' => $defaults->get('defaults.license'), 'authors' => $defaults->get('defaults.authors'), 'namespace' => $namespace);
     // create file
     \CCJson::write($target . 'blueprint.json', $blueprint, true);
     $ship = \CCOrbit_Ship::blueprint($blueprint, $target);
     // create event files
     if ($namespace) {
         // create forge instance
         $forge = new \CCForge_Php($namespace);
         // add header
         $forge->comment($this->make_comment_header($ship->name . ' ship', array('package' => $ship->name, 'authors' => $ship->authors, 'version' => $ship->version, 'copyright' => \CCConfig::create('shipyard')->get('defaults.copyright'))));
         // add class
         $forge->closure('class Ship extends \\CCOrbit_Ship', function () {
             $forge = new \CCForge_Php();
             // add init function
             echo $forge->closure('public function wake()', '// Do stuff', "initialize the ship\n\n" . "@return void");
             echo $forge->line(2);
             // add init function
             echo $forge->closure('public function install()', '// Do stuff', "install the ship\n\n" . "@return void");
             echo $forge->line(2);
             // add init function
             echo $forge->closure('public function unsintall()', '// Do stuff', "uninstall the ship\n\n" . "@return void");
         });
         \CCFile::write($target . CCDIR_CLASS . 'Ship' . EXT, $forge);
     } else {
         // create forge instance
         $forge = new \CCForge_Php();
         // add header
         $forge->comment($this->make_comment_header($ship->name, array('package' => $ship->name, 'authors' => $ship->authors, 'version' => $ship->version, 'copyright' => \CCConfig::create('shipyard')->get('defaults.copyright'))));
         \CCFile::write($target . 'shipyard/wake' . EXT, $forge);
         \CCFile::write($target . 'shipyard/install' . EXT, $forge);
         \CCFile::write($target . 'shipyard/uninstall' . EXT, $forge);
     }
     // sucess
     CCCli::line("'" . $name . "' succesfully created under: " . $target, 'green');
 }
Exemplo n.º 2
0
 /**
  * Get the current builder output
  *
  * @return string
  */
 public function output()
 {
     $namespace = null;
     $class = $this->name;
     extract(\CCConfig::create('shipyard')->defaults);
     // get namespace from the param
     if (strpos($class, '::') !== false) {
         list($namespace, $class) = explode('::', $this->name);
         // try to get the ship from namespace
         if ($ship = \CCOrbit::ship_by_namespace($namespace)) {
             $package = $ship->name;
             $version = $ship->version;
             $authors = $ship->authors;
         }
     }
     // create forge instance
     $forge = new \CCForge_Php($namespace);
     // add header
     $forge->comment($this->file_header($class, array('package' => $package, 'authors' => $authors, 'version' => $version, 'copyright' => $copyright)));
     $class_string = 'class ' . $class;
     // superclasses
     if ($this->extends) {
         $class_string .= ' extends ' . $this->extends;
     }
     // interface implementations
     if (!empty($this->implements)) {
         $class_string .= ' implements ' . implode(', ', $this->implements);
     }
     // create the closure
     $forge->closure($class_string, $this->output);
     return $forge->buffer;
 }