示例#1
0
 /**
  * Generate the model class and dbdeploy delta and then output the path
  * to each so that they can easily be found for editing.
  *
  * @return void
  */
 public function execute()
 {
     $inflector = new Inflector();
     if (null === $this->modelClass) {
         $this->modelClass = $inflector->classify($this->name);
     }
     $modelFile = $this->paths->getModels() . '/' . $this->modelClass . '.php';
     $dbdeployFile = $this->paths->getDb() . '/' . $this->getDbRevision() . '-add-' . $this->name . '.sql';
     if ($this->modelAlreadyExists($modelFile)) {
         return $this->abort("There is a already a model file named \"{$this->modelClass}.php\"");
     }
     if ($this->dbdeployFileAlreadyExists($dbdeployFile)) {
         return $this->abort("There is already a dbdeploy file at \"{$dbdeployFile}\"");
     }
     $templateReplacements = array('{{modelClass}}' => $this->modelClass, '{{tableName}}' => $this->name);
     $this->writeFile($modelFile, str_replace(array_keys($templateReplacements), $templateReplacements, file_get_contents(__DIR__ . '/gen-templates/db-table/ModelClass.tpl')));
     $templateReplacements = array('{{tableName}}' => $this->name, '{{primaryKey}}' => $inflector->singularize($this->name) . '_id');
     $this->writeFile($dbdeployFile, str_replace(array_keys($templateReplacements), $templateReplacements, file_get_contents(__DIR__ . '/gen-templates/db-table/dbdeploy-delta.sql')));
     $this->renderSuccessMessage($dbdeployFile, $modelFile);
 }