/** * Execute the console command. * * @return mixed */ public function handle() { if ($classname = $this->argument('name')) { $classname = ucfirst($classname); $template = $this->getTemplateDir() . $this->templateName; if (file_exists($template)) { if (file_exists(ModelCore::getModelDirectory())) { $text = str_replace($this->mergeCode, $classname, file_get_contents($template)); $tableDefine = $this->option('table') ? 'protected $table = \'' . $this->option('table') . '\';' : ''; $text = str_replace('{table-define}', $tableDefine, $text); $path = ModelCore::getModelDirectory() . $classname . $this->suffix . $this->ext; if (!file_exists($path)) { if (false == file_put_contents($path, $text)) { $this->error('Can\'t write file to ' . ControllerCore::getControllerDirectory() . $path); } else { chmod($path, 0766); $this->info($classname . ' Model class created.'); } } else { $this->error($classname . ' already exist'); } } else { $this->error('Model class directory not found ' . ControllerCore::getControllerDirectory()); } } else { $this->error('Model class template not found ' . $template); } } }