From 6d90d9c2b003c6c2b345fc4653592b1f8c7acd31 Mon Sep 17 00:00:00 2001 From: Morten Poul Jensen Date: Wed, 19 Jun 2019 08:32:59 +0200 Subject: [PATCH] Add ObserverCommand and RuleCommand --- config/domain-commands.php | 4 ++ src/Commands/ObserverCommand.php | 89 ++++++++++++++++++++++++++++++++ src/Commands/RuleCommand.php | 89 ++++++++++++++++++++++++++++++++ src/DomainServiceProvider.php | 4 ++ 4 files changed, 186 insertions(+) create mode 100644 src/Commands/ObserverCommand.php create mode 100644 src/Commands/RuleCommand.php diff --git a/config/domain-commands.php b/config/domain-commands.php index 4877161..66274b1 100644 --- a/config/domain-commands.php +++ b/config/domain-commands.php @@ -26,6 +26,10 @@ 'model' => null, + 'observer' => null, + + 'rule' => null, + ], ]; diff --git a/src/Commands/ObserverCommand.php b/src/Commands/ObserverCommand.php new file mode 100644 index 0000000..4729577 --- /dev/null +++ b/src/Commands/ObserverCommand.php @@ -0,0 +1,89 @@ +option('domain')) { + return "{$rootNamespace}\\{$domain}\\Observers"; + } + + $defaultNamespace = config('domain-commands.default_namespace'); + + return "{$rootNamespace}\\{$defaultNamespace}\\Observers"; + } + + /** + * Get the destination class path. + * + * @param string $name + * @return string + */ + protected function getPath($name) + { + return $this->laravel->basePath().'/app/'.str_replace('\\', '/', $name).'.php'; + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getStub() + { + $stubPath = config('domain-commands.stubs.rule'); + + if (! is_null($stubPath) && is_string($stubPath)) { + return $stubPath; + } + + return parent::getStub(); + } + + /** + * Get the root namespace for the class. + * + * @return string + */ + protected function rootNamespace() + { + return 'Domain\\'; + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array_merge(parent::getOptions(), [ + ['domain', 'd', InputOption::VALUE_OPTIONAL, 'Set the domain of the model'], + ]); + } +} diff --git a/src/Commands/RuleCommand.php b/src/Commands/RuleCommand.php new file mode 100644 index 0000000..ea722da --- /dev/null +++ b/src/Commands/RuleCommand.php @@ -0,0 +1,89 @@ +option('domain')) { + return "{$rootNamespace}\\{$domain}\\Rules"; + } + + $defaultNamespace = config('domain-commands.default_namespace'); + + return "{$rootNamespace}\\{$defaultNamespace}\\Rules"; + } + + /** + * Get the destination class path. + * + * @param string $name + * @return string + */ + protected function getPath($name) + { + return $this->laravel->basePath().'/app/'.str_replace('\\', '/', $name).'.php'; + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getStub() + { + $stubPath = config('domain-commands.stubs.rule'); + + if (! is_null($stubPath) && is_string($stubPath)) { + return $stubPath; + } + + return parent::getStub(); + } + + /** + * Get the root namespace for the class. + * + * @return string + */ + protected function rootNamespace() + { + return 'Domain\\'; + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array_merge(parent::getOptions(), [ + ['domain', 'd', InputOption::VALUE_OPTIONAL, 'Set the domain of the model'], + ]); + } +} diff --git a/src/DomainServiceProvider.php b/src/DomainServiceProvider.php index e652c0d..309dde4 100644 --- a/src/DomainServiceProvider.php +++ b/src/DomainServiceProvider.php @@ -5,9 +5,11 @@ use Illuminate\Support\ServiceProvider; use Signifly\Console\Commands\DTOCommand; use Signifly\Console\Commands\EnumCommand; +use Signifly\Console\Commands\RuleCommand; use Signifly\Console\Commands\EventCommand; use Signifly\Console\Commands\ModelCommand; use Signifly\Console\Commands\ActionCommand; +use Signifly\Console\Commands\ObserverCommand; class DomainServiceProvider extends ServiceProvider { @@ -24,6 +26,8 @@ public function boot() EnumCommand::class, EventCommand::class, ModelCommand::class, + ObserverCommand::class, + RuleCommand::class, ]); }