public function generate() { $templateData = $this->commandData->templatesHelper->getTemplate('Controller', 'api'); if ($this->commandData->pointerModel) { $pointerRelationship = []; foreach ($this->commandData->inputFields as $field) { if ($field['type'] == 'pointer') { $arr = explode(',', $field['typeOptions']); if (count($arr) > 0) { $modelName = $arr[0]; $pointerRelationship[] = "'" . Str::camel($modelName) . "'"; } } } $templateData = str_replace('$POINTER_MODELS_RELATIONSHIP$', "with([" . implode(", ", $pointerRelationship) . "])->", $templateData); } else { $templateData = str_replace('$POINTER_MODELS_RELATIONSHIP$', '', $templateData); } $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = $this->commandData->modelName . 'APIController.php'; if (!file_exists($this->path)) { mkdir($this->path, 0755, true); } $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->comment("\nAPI Controller created: "); $this->commandData->commandObj->info($fileName); }
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(); } }
private function generateMenu() { $menuContents = $this->commandData->fileHelper->getFileContents($this->path); $templateData = $this->commandData->templatesHelper->getTemplate('scaffold_menus', 'menus'); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $menuContents .= "\n\n" . $templateData; $this->commandData->fileHelper->writeFile($this->path, $menuContents); $this->commandData->commandObj->comment("\nmenus.blade.php modified:"); $this->commandData->commandObj->info('"' . $this->commandData->modelNamePluralCamel . '" menu added.'); }
private function generateShow() { $templateData = $this->commandData->templatesHelper->getTemplate('show.blade', $this->viewsPath); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = 'show.blade.php'; $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); \Log::info($fileName . ' Was Generated'); $this->commandData->commandObj->info('show.blade.php created'); }
private function generateScaffoldRoutes() { $routeContents = $this->commandData->fileHelper->getFileContents($this->scaffoldPath); $templateData = $this->commandData->templatesHelper->getTemplate('scaffold_route', 'routes'); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $routeContents .= "\n\n" . $templateData; $this->commandData->fileHelper->writeFile($this->scaffoldPath, $routeContents); $this->commandData->commandObj->comment("\nscaffold_routes.php modified:"); $this->commandData->commandObj->info('"' . $this->commandData->modelNamePluralCamel . '" route added.'); }
private function generateUpdateRequest() { $templateData = $this->commandData->templatesHelper->getTemplate('UpdateRequest', 'scaffold/requests'); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = 'Update' . $this->commandData->modelName . 'Request.php'; $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->comment("\nUpdate Request created: "); $this->commandData->commandObj->info($fileName); }
private function generateScaffoldBreadcrumbs() { $breadcrumbsContents = $this->commandData->fileHelper->getFileContents($this->path); $templateData = $this->commandData->templatesHelper->getTemplate("breadcrumbs", "scaffold"); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $breadcrumbsContents .= "\n\n" . $templateData; $this->commandData->fileHelper->writeFile($this->path, $breadcrumbsContents); $this->commandData->commandObj->comment("\nbreadcrumbs.php modified:"); $this->commandData->commandObj->info("\"" . $this->commandData->modelNamePluralCamel . "\" breadcrumb added."); }
private function generateAppBind() { $appBindContents = $this->commandData->fileHelper->getFileContents($this->path); $templateData = $this->commandData->templatesHelper->getTemplate("AppBind", "common"); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $appBindContents .= "\n\n" . $templateData; $this->commandData->fileHelper->writeFile($this->path, $appBindContents); $this->commandData->commandObj->comment("\nregister_app_bind.php modified:"); $this->commandData->commandObj->info("\"" . $this->commandData->modelNamePluralCamel . "\" \$this->app->bind() added."); }
public function generate() { $templateData = $this->commandData->templatesHelper->getTemplate('Controller', 'scaffold'); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = $this->commandData->modelName . 'Controller.php'; $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->comment("\nLive Controller created: "); \Log::info('' . $fileName . ' Was Generated'); $this->commandData->commandObj->info($fileName); }
public function generate() { $templateData = $this->commandData->templatesHelper->getTemplate('Migration', 'common'); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $templateData = str_replace('$FIELDS$', $this->generateFieldsStr(), $templateData); $fileName = date('Y_m_d_His') . '_' . 'create_' . $this->commandData->modelNamePluralCamel . '_table.php'; $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->comment("\nMigration created: "); $this->commandData->commandObj->info($fileName); }
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(); } }
function generate() { $templateData = $this->commandData->templatesHelper->getTemplate("FractalPresenter", "common"); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = $this->commandData->modelName . "APIPresenter.php"; if (!file_exists($this->path)) { mkdir($this->path, 0755, true); } $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->comment("\nAPIPresenter created: "); $this->commandData->commandObj->info($fileName); }
public function generate() { $templateData = $this->commandData->templatesHelper->getTemplate('Controller', 'api'); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = $this->commandData->modelName . 'APIController.php'; if (!file_exists($this->path)) { mkdir($this->path, 0755, true); } $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->comment("\nAPI Controller created: "); $this->commandData->commandObj->info($fileName); }
public function generate() { $templateData = $this->commandData->templatesHelper->getTemplate('Repository', 'common'); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = $this->commandData->modelName . 'Repository.php'; if (!file_exists($this->path)) { mkdir($this->path, 0755, true); } $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->comment("\nRepository created: "); \Log::info('' . $fileName . ' Was Generated'); $this->commandData->commandObj->info($fileName); }
public function generate() { $templateData = $this->commandData->templatesHelper->getTemplate("Controller", "scaffold"); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); if ($this->commandData->paginate) { $templateData = str_replace('$RENDER_TYPE$', 'paginate(' . $this->commandData->paginate . ')', $templateData); } else { $templateData = str_replace('$RENDER_TYPE$', 'all()', $templateData); } $fileName = $this->commandData->modelName . "Controller.php"; $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->comment("\nController created: "); $this->commandData->commandObj->info($fileName); }
private function fillTemplate($templateData) { if (!$this->commandData->useSoftDelete) { $templateData = str_replace('$SOFT_DELETE_IMPORT$', '', $templateData); $templateData = str_replace('$SOFT_DELETE$', '', $templateData); $templateData = str_replace('$SOFT_DELETE_DATES$', '', $templateData); } $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fillables = []; foreach ($this->commandData->inputFields as $field) { $fillables[] = '"' . $field['fieldName'] . '"'; } $templateData = str_replace('$FIELDS$', implode(",\n\t\t", $fillables), $templateData); $templateData = str_replace('$RULES$', implode(",\n\t\t", $this->generateRules()), $templateData); $templateData = str_replace('$CAST$', implode(",\n\t\t", $this->generateCasts()), $templateData); return $templateData; }
function generate() { $templateData = $this->commandData->templatesHelper->getTemplate("Repository", "common"); $fillables = []; foreach ($this->commandData->inputFields as $field) { $fillables[] = '"' . $field['fieldName'] . '" => ' . '"like"'; } $templateData = str_replace('$FIELDS$', implode(",\n\t\t", $fillables), $templateData); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = $this->commandData->modelName . "Repository.php"; if (!file_exists($this->path)) { mkdir($this->path, 0755, true); } $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->comment("\nRepository created: "); $this->commandData->commandObj->info($fileName); }
public function getInputFields() { $fields = []; $this->commandObj->info("Specify fields for the model (skip id & timestamp fields, will be added automatically)"); $this->commandObj->info("Left blank to finish"); while (true) { $fieldInputStr = $this->commandObj->ask("Field:"); if (empty($fieldInputStr)) { break; } if (!GeneratorUtils::validateFieldInput($fieldInputStr)) { $this->commandObj->error("Invalid Input. Try again"); continue; } $validations = $this->commandObj->ask("Enter validations: "); $fields[] = GeneratorUtils::processFieldInput($fieldInputStr, $validations); } return $fields; }
function generate() { $templateData = $this->commandData->templatesHelper->getTemplate("FractalTransformer", "common"); $transformer_fields = []; foreach ($this->commandData->inputFields as $field) { if (!in_array($field['fieldName'], ['id', 'created_at', 'updated_at'])) { $transformer_fields[] = "'" . $field['fieldName'] . "' => \$model->" . $field['fieldName'] . ","; } } $templateData = str_replace('$FIELDS$', implode("\n\t\t\t", $transformer_fields), $templateData); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = $this->commandData->modelName . "APIPresenterTransformer.php"; if (!file_exists($this->path)) { mkdir($this->path, 0755, true); } $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->comment("\nPresenterTransformer created: "); $this->commandData->commandObj->info($fileName); }
public function getInputFields() { $fields = []; $this->commandObj->info("Specify fields for the model (skip id & timestamp fields, will be added automatically)"); $this->commandObj->info("Enter exit to finish"); while (true) { $fieldInputStr = $this->commandObj->ask("Field:", ''); if (empty($fieldInputStr) || $fieldInputStr == false || $fieldInputStr == "exit") { break; } if (!GeneratorUtils::validateFieldInput($fieldInputStr)) { $this->commandObj->error("Invalid Input. Try again"); continue; } $type = $this->commandObj->ask("Enter field type (text): ", "text"); $validations = $this->commandObj->ask("Enter validations: ", false); $validations = $validations == false ? '' : $validations; $fields[] = GeneratorUtils::processFieldInput($fieldInputStr, $type, $validations); } return $fields; }
public function getInputFields() { $fields = []; $this->commandObj->info('Specify fields for the model (skip id & timestamp fields, will be added automatically)'); $this->commandObj->info('Enter exit to finish'); while (true) { $fieldInputStr = $this->commandObj->ask('Field: (field_name:field_database_type)', ''); if (empty($fieldInputStr) || $fieldInputStr == false || $fieldInputStr == 'exit') { break; } if (!GeneratorUtils::validateFieldInput($fieldInputStr)) { $this->commandObj->error('Invalid Input. Try again'); continue; } $type = $this->commandObj->ask('Enter field html input type (text): ', 'text'); $validations = $this->commandObj->ask('Enter validations: ', false); $validations = $validations == false ? '' : $validations; $fields[] = GeneratorUtils::processFieldInput($fieldInputStr, $type, $validations); } return $fields; }
/** * 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); }
public function generateFieldsFromTable() { $columns = $this->schema->listTableColumns($this->tableName); $fields = []; foreach ($columns as $column) { switch ($column->getType()->getName()) { case 'integer': $fieldInput = $this->generateIntFieldInput($column->getName(), 'integer', $column); $type = 'number'; break; case 'smallint': $fieldInput = $this->generateIntFieldInput($column->getName(), 'smallInteger', $column); $type = 'number'; break; case 'bigint': $fieldInput = $this->generateIntFieldInput($column->getName(), 'bigInteger', $column); $type = 'number'; break; case 'boolean': $fieldInput = $this->generateSingleFieldInput($column->getName(), 'boolean'); $type = 'text'; break; case 'datetime': $fieldInput = $this->generateSingleFieldInput($column->getName(), 'dateTime'); $type = 'date'; break; case 'datetimetz': $fieldInput = $this->generateSingleFieldInput($column->getName(), 'dateTimeTz'); $type = 'date'; break; case 'date': $fieldInput = $this->generateSingleFieldInput($column->getName(), 'date'); $type = 'date'; break; case 'time': $fieldInput = $this->generateSingleFieldInput($column->getName(), 'time'); $type = 'text'; break; case 'decimal': $fieldInput = $this->generateDecimalInput($column, 'decimal'); $type = 'number'; break; case 'float': $fieldInput = $this->generateFloatInput($column); $type = 'number'; break; case 'string': $fieldInput = $this->generateStringInput($column); $type = 'text'; break; case 'text': $fieldInput = $this->generateTextInput($column); $type = 'textarea'; break; default: $fieldInput = $this->generateTextInput($column); $type = 'text'; } if (strtolower($column->getName()) == 'password') { $type = 'password'; } elseif (strtolower($column->getName()) == 'email') { $type = 'email'; } if (!empty($fieldInput)) { // $fieldInput .= $this->checkForDefault($column); // $fieldInput .= $this->checkForNullable($column); // $fieldInput .= $this->checkForUnique($column); $fields[] = GeneratorUtils::processFieldInput($fieldInput, $type, ''); } } return $fields; }
private function generateEdit() { $langStr = "'edit_model'=>'Edit " . $this->commandData->modelName . "',\n"; $templateData = $this->commandData->templatesHelper->getTemplate('edit.blade', $this->viewsPath); $templateLang = $this->commandData->templatesHelper->getTemplate('edit', $this->langsPath); $templateLang = str_replace('$EDIT_LANG$', $langStr, $templateLang); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = 'edit.blade.php'; $path = $this->path . $fileName; $pathLang = $this->path_lang . str_replace('.blade', '', $fileName); $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->info('edit.blade.php created'); $this->commandData->fileHelper->writeFile($pathLang, $templateLang); $this->commandData->commandObj->info('edit.php created'); }
private function generateEdit() { $templateData = $this->commandData->templatesHelper->getTemplate("edit.blade", $this->viewsPath); $templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = "edit.blade.php"; $path = $this->path . $fileName; $this->commandData->fileHelper->writeFile($path, $templateData); $this->commandData->commandObj->info("edit.blade.php created"); }