Beispiel #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');
 }
Beispiel #2
0
 /**
  * Add a ship
  * this loads the ship loader file
  *
  * @param string		$path
  * @return bool
  */
 public static function enter($path)
 {
     if (!is_array($path)) {
         $path = array($path);
     }
     foreach ($path as $ship) {
         // load ship at path
         $ship = CCOrbit_Ship::create($ship);
         if (array_key_exists($ship->name, static::$ships)) {
             throw new CCException("CCOrbit::enter - {$ship->name} ship already entered.");
         }
         if ($ship->wake !== false) {
             $ship->event($ship->wake);
         }
         CCProfiler::check("CCOrbit - ship {$ship->name} launched.");
         // add to our loaded ships
         static::$ships[$ship->name] = $ship;
     }
 }