/** * print information about this application * * @param array $params */ public function action_info($params) { $app = \ClanCats::runtime(); // print the app name $this->line(\CCForge_Php::make('comment', $app::$name . PHP_EOL . "*" . PHP_EOL . "Running on ClanCatsFramework " . \ClanCats::VERSION . PHP_EOL . "© 2010 - " . date('Y') . " ClanCats GmbH" . PHP_EOL), 'cyan'); // list printer $list = function ($array) { foreach ($array as $key => $value) { $this->line($key . ': ' . CCCli::color($value, 'green')); } }; // print info $list(array('Runtime Class' => $app, 'CCF Version' => \ClanCats::version(), 'CCF Environment' => \ClanCats::environment(), 'Development env' => var_export(\ClanCats::in_development(), true), 'File extention' => EXT, 'Core namespace' => CCCORE_NAMESPACE)); // paths $this->line(PHP_EOL . "Paths", 'cyan'); $list(\ClanCats::paths()); // paths $this->line(PHP_EOL . "Directories", 'cyan'); $list(\ClanCats::directories()); // autoloader $this->line(PHP_EOL . "Autoloader - namespaces", 'cyan'); $list(\CCFinder::$namespaces); }
/** * Test closure */ public function testClosure() { // create new forge $forge = CCForge_Php::create(); // simpel property $this->assertEquals($forge->closure('public function test()', '// woosa'), "public function test()\n{\n\t// woosa\n}"); // with default $this->assertEquals($forge->property('public static $foo', 100), 'public static $foo = 100;'); // with default string $this->assertEquals($forge->property('public $foo', 'bar'), 'public $foo = \'bar\';'); // with default and comment $this->assertEquals($forge->property('public $foo', 'bar', 'foo var'), "/**\n * foo var\n */\npublic \$foo = 'bar';"); }
/** * 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'); }
/** * 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; }