Skip to content

Commit

Permalink
Use alias for deferred provider (#112)
Browse files Browse the repository at this point in the history
* Use alias for deferred provider

Fixes usage of multiple ide-helper hooks with deferred providers

* Fix phpstan warning

* Remove wrong import

* Refactoring

---------

Co-authored-by: Jonas Staudenmeir <[email protected]>
  • Loading branch information
daniel-de-wit and staudenmeir authored Feb 2, 2025
1 parent afb31ea commit 33f8b61
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/IdeHelperServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@

class IdeHelperServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
* @var string
*/
const ModelsCommandAlias = __NAMESPACE__ . '\\' . ModelsCommand::class;

public function boot(): void
{
// Laravel only allows a single deferred service provider to claim
// responsibility for a given class, interface, or service in the
// provides() method. To ensure this provider is properly loaded
// when running the ModelsCommand we bind an alias and use that instead.
$this->app->alias(ModelsCommand::class, static::ModelsCommandAlias);
}

public function register(): void
{
/** @var \Illuminate\Config\Repository $config */
Expand All @@ -24,12 +38,12 @@ public function register(): void
}

/**
* @return list<class-string<\Illuminate\Console\Command>>
* @return list<string>
*/
public function provides(): array
{
return [
ModelsCommand::class,
static::ModelsCommandAlias,
];
}
}

0 comments on commit 33f8b61

Please sign in to comment.