コード例 #1
0
ファイル: BaseCommand.php プロジェクト: belaidHUB/convention
 public function handle()
 {
     $this->commandData->modelName = $this->argument('model');
     $this->commandData->useSoftDelete = $this->option('softDelete');
     $this->commandData->useSearch = $this->option('search');
     $this->commandData->fieldsFile = $this->option('fieldsFile');
     $this->commandData->initVariables();
     if ($this->commandData->fieldsFile) {
         $fileHelper = new FileHelper();
         try {
             if (file_exists($this->commandData->fieldsFile)) {
                 $filePath = $this->commandData->fieldsFile;
             } else {
                 $filePath = base_path($this->commandData->fieldsFile);
             }
             if (!file_exists($filePath)) {
                 $this->commandData->commandObj->error("Fields file not found");
                 exit;
             }
             $fileContents = $fileHelper->getFileContents($filePath);
             $fields = json_decode($fileContents, true);
             $this->commandData->inputFields = GeneratorUtils::validateFieldsFile($fields);
         } catch (Exception $e) {
             $this->commandData->commandObj->error($e->getMessage());
             exit;
         }
     } else {
         $this->commandData->inputFields = $this->commandData->getInputFields();
     }
 }
コード例 #2
0
 public function handle()
 {
     $this->commandData->modelName = $this->argument('model');
     $this->commandData->useSoftDelete = $this->option('softDelete');
     $this->commandData->fieldsFile = $this->option('fieldsFile');
     $this->commandData->paginate = $this->option('paginate');
     $this->commandData->tableName = $this->option('tableName');
     $this->commandData->skipMigration = $this->option('skipMigration');
     $this->commandData->fromTable = $this->option('fromTable');
     $this->commandData->rememberToken = $this->option('rememberToken');
     $this->commandData->main_table_id = $this->option('mainTableId');
     $this->commandData->main_module = $this->option('mainModuleName');
     $this->commandData->sub_module = $this->option('subModuleName');
     $this->commandData->module_name = ucwords(str_replace("-", " ", $this->commandData->main_module));
     $this->commandData->model_primary_key = $this->option('primaryKey');
     $this->commandData->layout_name = $this->option('layoutName');
     if ($this->commandData->fromTable) {
         if (!$this->commandData->tableName) {
             $this->error('tableName required with fromTable option.');
             exit;
         }
     }
     if ($this->commandData->paginate <= 0) {
         $this->commandData->paginate = 10;
     }
     $this->commandData->initVariables();
     $this->commandData->addDynamicVariable('$NAMESPACE_APP$', $this->getLaravel()->getNamespace());
     $this->commandData->addDynamicVariable('$MAIN_TABLE_ID$', $this->commandData->main_table_id);
     $this->commandData->addDynamicVariable('$MAIN_MODULE$', $this->commandData->main_module);
     $this->commandData->addDynamicVariable('$SUB_MODULE', $this->commandData->sub_module);
     $this->commandData->addDynamicVariable('$MODULE_NAME', $this->commandData->module_name);
     $this->commandData->addDynamicVariable('$MODEL_PRIMARY_KEY$', $this->commandData->model_primary_key);
     $this->commandData->addDynamicVariable('$LAYOUT_NAME$', $this->commandData->layout_name);
     if ($this->commandData->fieldsFile) {
         $fileHelper = new FileHelper();
         try {
             if (file_exists($this->commandData->fieldsFile)) {
                 $filePath = $this->commandData->fieldsFile;
             } else {
                 $filePath = base_path($this->commandData->fieldsFile);
             }
             if (!file_exists($filePath)) {
                 $this->commandData->commandObj->error('Fields file not found');
                 exit;
             }
             $fileContents = $fileHelper->getFileContents($filePath);
             $fields = json_decode($fileContents, true);
             $this->commandData->inputFields = GeneratorUtils::validateFieldsFile($fields);
         } catch (Exception $e) {
             $this->commandData->commandObj->error($e->getMessage());
             exit;
         }
     } elseif ($this->commandData->fromTable) {
         $tableFieldsGenerator = new TableFieldsGenerator($this->commandData->tableName);
         $this->commandData->inputFields = $tableFieldsGenerator->generateFieldsFromTable();
     } else {
         $this->commandData->inputFields = $this->commandData->getInputFields();
     }
 }
コード例 #3
0
 public function handle()
 {
     $this->commandData->modelName = $this->argument('model');
     $this->commandData->useSoftDelete = $this->option('softDelete');
     $this->commandData->fieldsFile = $this->option('fieldsFile');
     $this->commandData->paginate = $this->option('paginate');
     $this->commandData->tableName = $this->option('tableName');
     $this->commandData->skipMigration = $this->option('skipMigration');
     $this->commandData->fromTable = $this->option('fromTable');
     $this->commandData->rememberToken = $this->option('rememberToken');
     if ($this->commandData->fromTable) {
         if (!$this->commandData->tableName) {
             $this->error('tableName required with fromTable option.');
             exit;
         }
     }
     if ($this->commandData->paginate <= 0) {
         $this->commandData->paginate = 10;
     }
     $this->commandData->initVariables();
     $this->commandData->addDynamicVariable('$NAMESPACE_APP$', $this->getLaravel()->getNamespace());
     if ($this->commandData->fieldsFile) {
         $fileHelper = new FileHelper();
         try {
             if (file_exists($this->commandData->fieldsFile)) {
                 $filePath = $this->commandData->fieldsFile;
             } else {
                 $filePath = base_path($this->commandData->fieldsFile);
             }
             if (!file_exists($filePath)) {
                 $this->commandData->commandObj->error('Fields file not found');
                 exit;
             }
             $fileContents = $fileHelper->getFileContents($filePath);
             $fields = json_decode($fileContents, true);
             $this->commandData->inputFields = GeneratorUtils::validateFieldsFile($fields);
         } catch (Exception $e) {
             $this->commandData->commandObj->error($e->getMessage());
             exit;
         }
     } elseif ($this->commandData->fromTable) {
         $tableFieldsGenerator = new TableFieldsGenerator($this->commandData->tableName);
         $this->commandData->inputFields = $tableFieldsGenerator->generateFieldsFromTable();
         if (isset($this->commandData->inputFields[0]['fieldName'])) {
             /**
              * First field of the table must be the primary key
              */
             $primaryKey = $this->commandData->inputFields[0]['fieldName'];
             /**
              *  By defaul the primary key will be "id". If you use the option "--fromTable", the
              *  first field will used to be primary key (do not work for composite primary key)
              */
             $this->commandData->addDynamicVariable('$PRIMARY_KEY$', $primaryKey);
         }
     } else {
         $this->commandData->inputFields = $this->commandData->getInputFields();
     }
 }
コード例 #4
0
 public function handle()
 {
     $this->commandData->modelName = $this->argument('model');
     $this->commandData->useSoftDelete = $this->option('softDelete');
     $this->commandData->fieldsFile = $this->option('fieldsFile');
     $this->commandData->fieldsData = $this->option('fieldsData');
     $this->commandData->paginate = $this->option('paginate');
     $this->commandData->tableName = $this->option('tableName');
     $this->commandData->skipMigration = $this->option('skipMigration');
     $this->commandData->fromTable = $this->option('fromTable');
     $this->commandData->rememberToken = $this->option('rememberToken');
     $this->commandData->pointerModel = $this->option('pointerModel');
     if ($this->commandData->fromTable) {
         if (!$this->commandData->tableName) {
             $this->error('tableName required with fromTable option.');
             exit;
         }
     }
     if ($this->commandData->paginate <= 0) {
         $this->commandData->paginate = 10;
     }
     $this->commandData->initVariables();
     $this->commandData->addDynamicVariable('$NAMESPACE_APP$', $this->getLaravel()->getNamespace());
     if ($this->commandData->fieldsFile) {
         $fileHelper = new FileHelper();
         try {
             if (file_exists($this->commandData->fieldsFile)) {
                 $filePath = $this->commandData->fieldsFile;
             } else {
                 $filePath = base_path($this->commandData->fieldsFile);
             }
             if (!file_exists($filePath)) {
                 $this->commandData->commandObj->error('Fields file not found');
                 exit;
             }
             $fileContents = $fileHelper->getFileContents($filePath);
             $fields = json_decode($fileContents, true);
             $this->commandData->inputFields = GeneratorUtils::validateFieldsFile($fields);
         } catch (Exception $e) {
             $this->commandData->commandObj->error($e->getMessage());
             exit;
         }
     } elseif ($this->commandData->fromTable) {
         $tableFieldsGenerator = new TableFieldsGenerator($this->commandData->tableName);
         $this->commandData->inputFields = $tableFieldsGenerator->generateFieldsFromTable();
     } elseif ($this->commandData->fieldsData) {
         $fields = $this->commandData->fieldsData;
         $this->commandData->inputFields = GeneratorUtils::validateFieldsFile($fields);
     } else {
         $this->commandData->inputFields = $this->commandData->getInputFields();
     }
 }
コード例 #5
0
 /**
  * Publishes base controller.
  */
 private function publishAppBaseController()
 {
     $templateHelper = new TemplatesHelper();
     $templateData = $templateHelper->getTemplate('AppBaseController', 'controller');
     $templateData = GeneratorUtils::fillTemplate(CommandData::getConfigDynamicVariables(), $templateData);
     $fileName = 'AppBaseController.php';
     $filePath = Config::get('generator.path_controller', app_path('Http/Controllers/'));
     $fileHelper = new FileHelper();
     $fileHelper->writeFile($filePath . $fileName, $templateData);
     $this->comment('AppBaseController generated');
     $this->info($fileName);
 }