Skip to content

Commit

Permalink
Merge pull request #217 from apiato/API-1048-EventServiceProvider-won…
Browse files Browse the repository at this point in the history
…-t-get-registered-in-MainServiceProvider

fix(generator): EventServiceProvider don't get registered correctly
  • Loading branch information
Mohammad-Alavi authored Dec 13, 2024
2 parents e20b4b4 + dd33af4 commit 3967f60
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
25 changes: 17 additions & 8 deletions src/Generator/Commands/ContainerApiGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = [
Expand Down
3 changes: 3 additions & 0 deletions src/Generator/Commands/ServiceProviderGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 2 additions & 6 deletions src/Generator/Stubs/providers/main-service-provider.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 3967f60

Please sign in to comment.