public function rollback() { if (Str::contains($this->menuContents, $this->menuTemplate)) { file_put_contents($this->path, str_replace($this->menuTemplate, '', $this->menuContents)); $this->commandData->commandComment('menu deleted'); } }
public function rollback() { if (Str::contains($this->routeContents, $this->routesTemplate)) { $this->routeContents = str_replace($this->routesTemplate, '', $this->routeContents); file_put_contents($this->path, $this->routeContents); $this->commandData->commandComment('scaffold routes deleted'); } }
public function rollback() { if ($this->rollbackFile($this->path, $this->createFileName)) { $this->commandData->commandComment('Create API Request file deleted: ' . $this->createFileName); } if ($this->rollbackFile($this->path, $this->updateFileName)) { $this->commandData->commandComment('Update API Request file deleted: ' . $this->updateFileName); } }
public function generate() { $routeContents = file_get_contents($this->path); $routesTemplate = TemplateUtil::getTemplate('scaffold.routes.routes', 'laravel-generator'); $routesTemplate = TemplateUtil::fillTemplate($this->commandData->dynamicVars, $routesTemplate); $routeContents .= "\n\n" . $routesTemplate; file_put_contents($this->path, $routeContents); $this->commandData->commandComment("\n" . $this->commandData->modelNames['camelPlural'] . ' routes added.'); }
private function generateUpdateRequest() { $templateData = TemplateUtil::getTemplate('scaffold.request.update_request', 'laravel-generator'); $templateData = TemplateUtil::fillTemplate($this->commandData->dynamicVars, $templateData); $fileName = 'Update' . $this->commandData->modelName . 'Request.php'; FileUtil::createFile($this->path, $fileName, $templateData); $this->commandData->commandComment("\nUpdate Request created: "); $this->commandData->commandInfo($fileName); }
private function fillDocs($templateData) { if ($this->commandData->getAddOn('swagger')) { $templateData = $this->generateSwagger($templateData); } else { $docsTemplate = TemplateUtil::getTemplate('docs.model', 'laravel-generator'); $docsTemplate = TemplateUtil::fillTemplate($this->commandData->dynamicVars, $docsTemplate); $templateData = str_replace('$DOCS$', $docsTemplate, $templateData); } return $templateData; }
private function generateFields() { $fields = ["\$table->increments('id');"]; foreach ($this->commandData->inputFields as $field) { if ($field['fieldName'] == "id") { continue; } $fields[] = SchemaUtil::createField($field); } $fields[] = "\$table->timestamps();"; if ($this->commandData->getOption('softDelete')) { $fields[] = "\$table->softDeletes();"; } return implode("\n\t\t\t", $fields); }
public function generate() { $templateData = TemplateUtil::getTemplate('scaffold.controller.controller', 'laravel-generator'); $templateData = TemplateUtil::fillTemplate($this->commandData->dynamicVars, $templateData); $paginate = $this->commandData->getOption('paginate'); if ($paginate) { $templateData = str_replace('$RENDER_TYPE$', 'paginate(' . $paginate . ')', $templateData); } else { $templateData = str_replace('$RENDER_TYPE$', 'all()', $templateData); } $fileName = $this->commandData->modelName . 'Controller.php'; FileUtil::createFile($this->path, $fileName, $templateData); $this->commandData->commandComment("\nController created: "); $this->commandData->commandInfo($fileName); }
public function generate() { $templateData = TemplateUtil::getTemplate('repository', 'laravel-generator'); $templateData = TemplateUtil::fillTemplate($this->commandData->dynamicVars, $templateData); $fillables = []; foreach ($this->commandData->inputFields as $field) { if ($field['searchable']) { $fillables[] = '"' . $field['fieldName'] . '"'; } } $templateData = str_replace('$FIELDS$', implode(",\n\t\t", $fillables), $templateData); $fileName = $this->commandData->modelName . 'Repository.php'; FileUtil::createFile($this->path, $fileName, $templateData); $this->commandData->commandComment("\nRepository created: "); $this->commandData->commandInfo($fileName); }
private function generateUpdate() { $templateData = TemplateUtil::getTemplate('scaffold.views.edit', $this->templateType); $templateData = TemplateUtil::fillTemplate($this->commandData->dynamicVars, $templateData); FileUtil::createFile($this->path, 'edit.blade.php', $templateData); $this->commandData->commandInfo('edit.blade.php created'); }
private function fillDocs($templateData) { $methods = ['controller', 'index', 'store', 'store', 'show', 'update', 'destroy']; if ($this->commandData->getAddOn('swagger')) { $templatePrefix = 'controller'; $templateType = 'swagger-generator'; } else { $templatePrefix = 'api.docs.controller'; $templateType = 'laravel-generator'; } foreach ($methods as $method) { $key = '$DOC_' . strtoupper($method) . '$'; $docTemplate = TemplateUtil::getTemplate($templatePrefix . '.' . $method, $templateType); $docTemplate = TemplateUtil::fillTemplate($this->commandData->dynamicVars, $docTemplate); $templateData = str_replace($key, $docTemplate, $templateData); } return $templateData; }
public function rollback() { $files = ['table.blade.php', 'index.blade.php', 'fields.blade.php', 'create.blade.php', 'edit.blade.php', 'show.blade.php', 'show_fields.blade.php']; foreach ($files as $file) { if ($this->rollbackFile($this->path, $file)) { $this->commandData->commandComment($file . ' file deleted'); } } }
public function rollback() { $fileName = 'create_' . $this->commandData->config->tableName . '_table.php'; /** @var SplFileInfo $allFiles */ $allFiles = File::allFiles($this->path); $files = []; foreach ($allFiles as $file) { $files[] = $file->getFilename(); } $files = array_reverse($files); foreach ($files as $file) { if (Str::contains($file, $fileName)) { if ($this->rollbackFile($this->path, $file)) { $this->commandData->commandComment('Migration file deleted: ' . $file); } break; } } }
private function generateShowFields() { $fieldTemplate = TemplateUtil::getTemplate('scaffold.views.show_field', $this->templateType); $fieldsStr = ''; foreach ($this->commandData->inputFields as $field) { $singleFieldStr = str_replace('$FIELD_NAME_TITLE$', Str::title(str_replace('_', ' ', $field['fieldName'])), $fieldTemplate); $singleFieldStr = str_replace('$FIELD_NAME$', $field['fieldName'], $singleFieldStr); $singleFieldStr = TemplateUtil::fillTemplate($this->commandData->dynamicVars, $singleFieldStr); $fieldsStr .= $singleFieldStr . "\n\n"; } $fileName = 'show_fields.blade.php'; FileUtil::createFile($this->path, $fileName, $fieldsStr); $this->commandData->commandInfo('show_fields.blade.php created'); }
/** * Execute the command. * * @return void */ public function handle() { if (!in_array($this->argument('type'), [CommandData::$COMMAND_TYPE_API, CommandData::$COMMAND_TYPE_SCAFFOLD, CommandData::$COMMAND_TYPE_API_SCAFFOLD])) { $this->error('invalid rollback type'); } $this->commandData = new CommandData($this, $this->argument('type')); $this->commandData->config->mName = $this->commandData->modelName = $this->argument('model'); $this->commandData->config->prepareOptions($this->commandData, ['tableName', 'prefix']); $this->commandData->config->prepareAddOns(); $this->commandData->config->prepareModelNames(); $this->commandData->config->prepareTableName(); $this->commandData->config->loadPaths(); $this->commandData->config->loadNamespaces($this->commandData); $this->commandData = $this->commandData->config->loadDynamicVariables($this->commandData); $migrationGenerator = new MigrationGenerator($this->commandData); $migrationGenerator->rollback(); $modelGenerator = new ModelGenerator($this->commandData); $modelGenerator->rollback(); $repositoryGenerator = new RepositoryGenerator($this->commandData); $repositoryGenerator->rollback(); $requestGenerator = new APIRequestGenerator($this->commandData); $requestGenerator->rollback(); $controllerGenerator = new APIControllerGenerator($this->commandData); $controllerGenerator->rollback(); $routesGenerator = new APIRoutesGenerator($this->commandData); $routesGenerator->rollback(); $requestGenerator = new RequestGenerator($this->commandData); $requestGenerator->rollback(); $controllerGenerator = new ControllerGenerator($this->commandData); $controllerGenerator->rollback(); $viewGenerator = new ViewGenerator($this->commandData); $viewGenerator->rollback(); $routeGenerator = new RoutesGenerator($this->commandData); $routeGenerator->rollback(); if ($this->commandData->getAddOn('tests')) { $repositoryTestGenerator = new RepositoryTestGenerator($this->commandData); $repositoryTestGenerator->rollback(); $testTraitGenerator = new TestTraitGenerator($this->commandData); $testTraitGenerator->rollback(); $apiTestGenerator = new APITestGenerator($this->commandData); $apiTestGenerator->rollback(); } if ($this->commandData->config->getAddOn('menu.enabled')) { $menuGenerator = new MenuGenerator($this->commandData); $menuGenerator->rollback(); } $this->info('Generating autoload files'); $this->composer->dumpOptimized(); }
private function saveSchemaFile() { $fileFields = []; foreach ($this->commandData->inputFields as $field) { $fileFields[] = ['fieldInput' => $field['fieldInput'], 'htmlType' => $field['htmlType'], 'validations' => $field['validations'], 'searchable' => $field['searchable'], 'fillable' => $field['fillable'], 'primary' => $field['primary'], 'inForm' => $field['inForm'], 'inIndex' => $field['inIndex']]; } $path = config('infyom.laravel_generator.path.schema_files', base_path('resources/model_schemas/')); $fileName = $this->commandData->modelName . '.json'; if (file_exists($path . $fileName) && !$this->confirmOverwrite($fileName)) { return; } FileUtil::createFile($path, $fileName, json_encode($fileFields, JSON_PRETTY_PRINT)); $this->commandData->commandComment("\nSchema File saved: "); $this->commandData->commandInfo($fileName); }
public function initScaffoldGeneratorCommandData() { $this->commandData->addDynamicVariable('$NAMESPACE_CONTROLLER$', config('infyom.laravel_generator.namespace.controller', 'App\\Http\\Controllers')); $this->commandData->addDynamicVariable('$NAMESPACE_REQUEST$', config('infyom.laravel_generator.namespace.request', 'App\\Http\\Requests')); $this->commandData->setOption('paginate', $this->option('paginate')); }
public function prepareOptions(CommandData &$commandData, $options = null) { if (empty($options)) { $options = self::$availableOptions; } foreach ($options as $option) { $this->options[$option] = $commandData->commandObj->option($option); } if (isset($options['fromTable']) and $this->options['fromTable']) { if (!$this->options['tableName']) { $commandData->commandError('tableName required with fromTable option.'); exit; } } $this->options['softDelete'] = config('infyom.laravel_generator.options.softDelete', false); if (!empty($this->options['skip'])) { $this->options['skip'] = array_map('trim', explode(',', $this->options['skip'])); } if (!empty($this->options['datatables'])) { if (strtolower($this->options['datatables']) == 'true') { $this->addOns['datatables'] = true; } else { $this->addOns['datatables'] = false; } } }
public function rollback() { if ($this->rollbackFile($this->path, $this->fileName)) { $this->commandData->commandComment('Model file deleted: ' . $this->fileName); } }
public function rollback() { if (Str::contains($this->menuContents, $this->menuTemplate)) { $this->commandData->commandComment('menu deleted'); } }