Exemplo n.º 1
0
 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();
     }
 }
 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();
     }
 }
 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();
     }
 }
 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();
     }
 }
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $namespace = $this->argument('namespace');
     $templateHelper = new TemplatesHelper();
     $templateData = $templateHelper->getTemplate('AppBaseController', 'Controller');
     $templateData = str_replace('$$BASE_NAMESPACE$$', $namespace, $templateData);
     $fileName = "AppBaseController.php";
     $filePath = __DIR__ . "/../../Controller/";
     $fileHelper = new FileHelper();
     $fileHelper->writeFile($filePath . $fileName, $templateData);
     $this->comment('AppBaseController generated');
     $this->info($fileName);
 }
 /**
  * Initialize routes group based on route integration.
  */
 private function initAPIRoutes()
 {
     $path = Config::get('generator.path_routes', app_path('Http/routes.php'));
     $fileHelper = new FileHelper();
     $routeContents = $fileHelper->getFileContents($path);
     $useDingo = Config::get('generator.use_dingo_api', false);
     if ($useDingo) {
         $template = 'dingo_api_routes_group';
     } else {
         $template = 'api_routes_group';
     }
     $templateHelper = new TemplatesHelper();
     $templateData = $templateHelper->getTemplate($template, 'routes');
     $templateData = $this->fillTemplate($templateData);
     $fileHelper->writeFile($path, $routeContents . "\n\n" . $templateData);
     $this->comment("\nAPI group added to routes.php");
 }
Exemplo n.º 7
0
 private function initAdminRoutes()
 {
     $path = Config::get('generator.path_routes', app_path('Http/routes.php'));
     $fileHelper = new FileHelper();
     $routeContents = $fileHelper->getFileContents($path);
     $template = 'admin_routes_group';
     $templateHelper = new TemplatesHelper();
     $templateData = $templateHelper->getTemplate($template, 'routes');
     $templateData = $this->fillTemplate($templateData);
     $fileHelper->writeFile($path, $routeContents . "\n\n" . $templateData);
     $this->comment("\n ADMIN group added to routes.php");
 }