/** * Execute the console command. * * @return void */ public function fire() { $name = $this->argument('name'); $path = $this->getPath(); $this->generator->setOptions($this->option()); // common error for field types $fields = $this->option('fields'); $fields = GeneratorsServiceProvider::mapFieldTypes($fields); $this->fields = $fields; $created = $this->generator->parse($name, $fields)->make($path, null, $finalPath); //$this->call('dump-autoload'); $this->printResult($created, $path, $finalPath); }
/** * Execute the console command. * * @throws MissingFieldsException * @throws TemplateNameDoesNotExist */ public function fire() { $this->generator->setOptions($this->option()); // Scaffolding should always begin with the singular // form of the now. $this->model = Pluralizer::singular($this->argument('name')); // common error for field types $fields = trim($this->option('fields')); $fields = GeneratorsServiceProvider::mapFieldTypes($fields); $this->fields = $fields; $templateDir = str_finish($this->option('template-dir'), "/"); $defaultDirs = $this->getDefaultTemplateSubDirs(); if ($this->fields === null) { throw new MissingFieldsException('You must specify the fields option.'); } if (!is_dir(GeneratorsServiceProvider::getTemplatePath($this->templateDirs, '/'))) { throw new TemplateNameDoesNotExist('template-name ' . $this->templateDirs . ' is not a sub-directory or templates/.'); } $templateDir = str_finish($templateDir, "/"); $isDefault = false; foreach ($defaultDirs as &$defaultDir) { $defaultDir = str_finish($defaultDir, "/"); if ($templateDir === $defaultDir) { $isDefault = true; } } $this->templateDirs = $isDefault ? [] : [$templateDir]; $this->templateDirs = array_merge($this->templateDirs, $defaultDirs); // We're going to need access to these values // within future commands. I'll save them // to temporary files to allow for that. $this->cache->fields($this->fields); $this->cache->modelName($this->model); $this->generateModel(); $this->generateController(); $this->generateViews(); $this->generateMigration(); if (!$this->option('bench')) { $this->generateSeed(); } $this->generateTranslations(); if (get_called_class() === 'Vsch\\Generators\\Commands\\ScaffoldGeneratorCommand') { $this->generateLangScaffold(); } if (get_called_class() === 'Vsch\\Generators\\Commands\\ScaffoldGeneratorCommand') { $this->generateTest(); } $routesFile = parent::getSrcPath(self::PATH_ROUTES); if ($routesFile) { if ($this->generator->updateRoutesFile($routesFile, $this->model, $this->getRouteTemplatePath())) { $this->info('Updated ' . $routesFile); } else { $this->warn('Did not need to update ' . $routesFile); } } else { $this->info(self::PATH_ROUTES . ' dir_map not set to a value in config, routes need to be manually updated'); } // We're all finished, so we // can delete the cache. $this->cache->destroyAll(); }