Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use alias for deferred provider #282

Merged
merged 2 commits into from
Feb 2, 2025
Merged

Conversation

daniel-de-wit
Copy link
Contributor

This PR changes the way the deferred service provider is loaded after the ide-helper ModelsCommand is requested from the container.

I only found out about this issue when using multiple packages using the ModelsCommand within the providers method of the deferred service provider. Where only one of the hooks was actually registered properly when running the models command.

Apparently Laravel only allows a single deferred service provider to claim responsibility for a given class, interface, or service in the provides() method.

You can confirm this by checking the bootstrap/cache/services.php after a composer dump-autoload:

'deferred' =>
array (
    'Barryvdh\\LaravelIdeHelper\\Console\\ModelsCommand' => 'Barryvdh\\LaravelIdeHelper\\IdeHelperServiceProvider',
)

After installing this package you can see it hijacked the binding:

'deferred' =>
array (
    'Barryvdh\\LaravelIdeHelper\\Console\\ModelsCommand' => 'Staudenmeir\\LaravelAdjacencyList\\IdeHelperServiceProvider',
)

To easiest solution is to use an alias for the ModelsCommand to prevent hijacking the binding. Resulting in a non-invasive binding.

'deferred' =>
array (
    'Barryvdh\\LaravelIdeHelper\\Console\\ModelsCommand' => 'Barryvdh\\LaravelIdeHelper\\IdeHelperServiceProvider',
    'ModelsCommand__LaravelAdjacencyList__alias' => 'Staudenmeir\\LaravelAdjacencyList\\IdeHelperServiceProvider',
)

daniel-de-wit and others added 2 commits January 31, 2025 11:58
Fixes usage of multiple ide-helper hooks with deferred providers
@staudenmeir staudenmeir merged commit 9c0945d into staudenmeir:main Feb 2, 2025
41 checks passed
@staudenmeir
Copy link
Owner

Thanks! I released a new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants