diff --git a/src/Generator/Commands/ContainerApiGenerator.php b/src/Generator/Commands/ContainerApiGenerator.php index 518b0d052..d8c99736e 100644 --- a/src/Generator/Commands/ContainerApiGenerator.php +++ b/src/Generator/Commands/ContainerApiGenerator.php @@ -81,14 +81,6 @@ public function getUserInputs(): array|null '--file' => Str::camel($this->sectionName) . '-' . Str::camel($this->containerName), ]); - $this->printInfoMessage('Generating MainServiceProvider'); - $this->call('apiato:generate:provider', [ - '--section' => $sectionName, - '--container' => $containerName, - '--file' => 'MainServiceProvider', - '--stub' => 'main-service-provider', - ]); - $this->printInfoMessage('Generating Model and Repository'); $this->call('apiato:generate:model', [ '--section' => $sectionName, @@ -417,6 +409,23 @@ public function getUserInputs(): array|null '--stub' => $stub, '--event-listeners' => $listeners, ]); + + $this->printInfoMessage('Generating MainServiceProvider'); + $this->call('apiato:generate:provider', [ + '--section' => $sectionName, + '--container' => $containerName, + '--file' => 'MainServiceProvider', + '--stub' => 'main-service-provider-with-event-provider', + '--event-service-provider' => 'EventServiceProvider', + ]); + } else { + $this->printInfoMessage('Generating MainServiceProvider'); + $this->call('apiato:generate:provider', [ + '--section' => $sectionName, + '--container' => $containerName, + '--file' => 'MainServiceProvider', + '--stub' => 'main-service-provider', + ]); } $generateComposerFile = [ diff --git a/src/Generator/Commands/ServiceProviderGenerator.php b/src/Generator/Commands/ServiceProviderGenerator.php index bd4f003ff..606b9906e 100644 --- a/src/Generator/Commands/ServiceProviderGenerator.php +++ b/src/Generator/Commands/ServiceProviderGenerator.php @@ -16,6 +16,7 @@ class ServiceProviderGenerator extends GeneratorCommand implements ComponentsGen public array $inputs = [ ['stub', null, InputOption::VALUE_OPTIONAL, 'The stub file to load for this generator.'], ['event-listeners', null, InputOption::VALUE_OPTIONAL, 'The Event Listeners that this Provider should register.'], + ['event-service-provider', null, InputOption::VALUE_OPTIONAL, 'The Event Service Provider that this Provider should register.'], ]; /** * The console command name. @@ -52,6 +53,7 @@ class ServiceProviderGenerator extends GeneratorCommand implements ComponentsGen public function getUserInputs(): array|null { $stub = $this->option('stub'); + $eventServiceProvider = $this->option('event-service-provider'); if (!$stub) { $stub = $this->checkParameterOrChoice( 'stub', @@ -126,6 +128,7 @@ public function getUserInputs(): array|null 'class-name' => $this->fileName, 'event-listeners' => $eventListenersString, 'use-statements' => $useStatements, + 'event-service-provider' => $eventServiceProvider, ], 'file-parameters' => [ 'file-name' => $this->fileName, diff --git a/src/Generator/Stubs/providers/main-service-provider-with-event-provider.stub b/src/Generator/Stubs/providers/main-service-provider-with-event-provider.stub index 803563e2f..f09c61455 100644 --- a/src/Generator/Stubs/providers/main-service-provider-with-event-provider.stub +++ b/src/Generator/Stubs/providers/main-service-provider-with-event-provider.stub @@ -11,12 +11,10 @@ use App\Ship\Parents\Providers\MainServiceProvider as ParentMainServiceProvider; class {{class-name}} extends ParentMainServiceProvider { public array $serviceProviders = [ - // InternalServiceProviderExample::class, + {{event-service-provider}}::class, ]; - public array $aliases = [ - // 'Foo' => Bar::class, - ]; + public array $aliases = []; public function register(): void { diff --git a/src/Generator/Stubs/providers/main-service-provider.stub b/src/Generator/Stubs/providers/main-service-provider.stub index 803563e2f..db5cbe809 100644 --- a/src/Generator/Stubs/providers/main-service-provider.stub +++ b/src/Generator/Stubs/providers/main-service-provider.stub @@ -10,13 +10,9 @@ use App\Ship\Parents\Providers\MainServiceProvider as ParentMainServiceProvider; */ class {{class-name}} extends ParentMainServiceProvider { - public array $serviceProviders = [ - // InternalServiceProviderExample::class, - ]; + public array $serviceProviders = []; - public array $aliases = [ - // 'Foo' => Bar::class, - ]; + public array $aliases = []; public function register(): void {