/** * generate a model class * * exmample: * run shipyard::model <class> * run shipyard::model <class> <table> * run shipyard::model <namespace>::<class> * * @param array $params * @return void */ public function action_model($params) { $options = \CCDataObject::assign($params); // params $name = $options->get(0, null); $table = $options->get(1, null); // get name if we dont have one while (!$name) { $name = $this->read('Please enter the class name: '); } // get table if we dont have one while (!$table) { $table = $this->read('Please enter the table name: '); } // resolve the path if (!($path = \CCPath::classes(str_replace('_', '/', $name), EXT))) { $this->error('Could not resolve the path. Check if the namespace is registered.'); return; } // create the class $model = \CCShipyard::create('dbmodel', $name, $table); // auto timestamps $model->timestamps($options->get('timestamps', false)); // check before if (file_exists($path)) { if (!CCCli::confirm("The class already exists. Do you wish to overwrite it?", true)) { return; } } // write file \CCFile::write($path, $model->output()); }
/** * Write the file down * * @return bool */ public function write() { // resolve the path if (!($path = \CCPath::classes(str_replace('_', '/', $this->name), EXT))) { throw new CCException('Could not resolve the class path. Check if the namespace is registered.'); } }