diff --git a/src/Commands/GeneratorCommand.php b/src/Commands/GeneratorCommand.php index c7588d4..68e336f 100644 --- a/src/Commands/GeneratorCommand.php +++ b/src/Commands/GeneratorCommand.php @@ -14,6 +14,7 @@ abstract class GeneratorCommand extends \Illuminate\Console\GeneratorCommand imp { use Concerns\CodeGenerator; use Concerns\TestGenerator; + use Concerns\UsesGeneratorOverrides; /** * Create a new controller creator command instance. diff --git a/src/Concerns/CodeGenerator.php b/src/Concerns/CodeGenerator.php index 4306fcc..83c8304 100644 --- a/src/Concerns/CodeGenerator.php +++ b/src/Concerns/CodeGenerator.php @@ -102,7 +102,12 @@ protected function getPath($name) { $name = Str::replaceFirst($this->rootNamespace(), '', $name); - return $this->generatorPreset()->sourcePath().'/'.str_replace('\\', '/', $name).'.php'; + return $this->getSourcePath().'/'.str_replace('\\', '/', $name).'.php'; + } + + protected function getSourcePath() + { + return $this->generatorPreset()->sourcePath(); } /** diff --git a/src/Concerns/CreatesUsingGeneratorPreset.php b/src/Concerns/CreatesUsingGeneratorPreset.php index df5bff4..630d4ca 100644 --- a/src/Concerns/CreatesUsingGeneratorPreset.php +++ b/src/Concerns/CreatesUsingGeneratorPreset.php @@ -33,4 +33,13 @@ protected function generatorPreset() { return $this->laravel->make(PresetManager::class)->driver($this->option('preset')); } + + + /** + * Get the generator preset source path. + */ + protected function getGeneratorSourcePath(): string + { + return $this->generatorPreset()->sourcePath(); + } } diff --git a/src/Concerns/UsesGeneratorOverrides.php b/src/Concerns/UsesGeneratorOverrides.php new file mode 100644 index 0000000..23e9301 --- /dev/null +++ b/src/Concerns/UsesGeneratorOverrides.php @@ -0,0 +1,52 @@ +rootNamespace(), '', $name); + + return $this->getGeneratorSourcePath().'/'.str_replace('\\', '/', $name).'.php'; + } + + /** + * Get the root namespace for the class. + * + * @return string + */ + protected function rootNamespace() + { + return $this->generatorPreset()->rootNamespace(); + } + + /** + * Get the model for the default guard's user provider. + * + * @return string|null + */ + protected function userProviderModel() + { + return $this->generatorPreset()->userProviderModel(); + } + + /** + * Get the first view directory path from the application configuration. + * + * @param string $path + * @return string + */ + protected function viewPath($path = '') + { + $views = $this->generatorPreset()->viewPath(); + + return $views.($path ? DIRECTORY_SEPARATOR.$path : $path); + } +}