Mercurial > packages > magicforger
diff src/Generator/BaseGenerator.php @ 4:a20439b1c9d3
Added Model generator and other updates.
| author | luka |
|---|---|
| date | Tue, 27 Jun 2023 20:16:55 -0400 |
| parents | 6468684362c2 |
| children | b0b2e79ad8e6 |
line wrap: on
line diff
--- a/src/Generator/BaseGenerator.php Tue Jun 27 15:32:47 2023 -0400 +++ b/src/Generator/BaseGenerator.php Tue Jun 27 20:16:55 2023 -0400 @@ -36,6 +36,8 @@ */ public function handle() { + + // First we need to ensure that the table exists, then we can if (! $this->tableExists($this->getTableInput())) { $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); @@ -43,31 +45,19 @@ return false; } - $name = $this->qualifyClass($this->getTableInput()); - - $path = $this->getPath($name); - - $file = $this->getFile($name); + $path = $this->getPath(); - dd($this->get_all_inserts($file)); + $file = $this->getFile($path); - // Next, we will generate the path to the location where this class' file should get - // written. Then, we will build the class and make the proper replacements on the - // file so that it gets the correctly formatted namespace and class name. + $file = $this->apply_replacements($file); + $this->makeDirectory($path); - $this->files->put($path, $this->sortImports($this->buildClass($name))); + $this->files->put($path, $this->sortImports($file)); $info = $this->type; - if (in_array(CreatesMatchingTest::class, class_uses_recursive($this))) { - if ($this->handleTestCreation($path)) { - $info .= ' and test'; - } - } - $this->components->info(sprintf('%s [%s] created successfully.', $info, $path)); - } /** @@ -129,6 +119,7 @@ protected function getOptions() { return [ + ['fresh', 'f', InputOption::VALUE_NONE, 'Start from the stub or use existing if possible.'], ]; } @@ -142,6 +133,14 @@ } /** + * Determines if the file exists + */ + protected function fileExists(string $path): bool + { + return $this->files->exists($path); + } + + /** * Gets the file that will be worked on. If there is already an existing file * then we can open that. However if we are forcing the operation, then we * will start with an empty stub. @@ -149,12 +148,11 @@ */ protected function getFile($name) { - - if ((! $this->hasOption('force') || - ! $this->option('force')) && - $this->alreadyExists($name)) { + if ((! $this->hasOption('fresh') || + ! $this->option('fresh')) && + $this->fileExists($name)) { //Working with an existing file - $this->files->get($name); + return $this->files->get($name); } //Working with a stub @@ -171,6 +169,7 @@ return trim($this->argument('table')); } + /** * Determines if the table exists in the current database */
