Skip to content

[7.x] Add methods to determine if service provider is loaded#33286

Merged
taylorotwell merged 2 commits intolaravel:7.xfrom
cybercog:add-application-is-provider-loaded-method
Jun 20, 2020
Merged

[7.x] Add methods to determine if service provider is loaded#33286
taylorotwell merged 2 commits intolaravel:7.xfrom
cybercog:add-application-is-provider-loaded-method

Conversation

@antonkomarev
Copy link
Contributor

@antonkomarev antonkomarev commented Jun 19, 2020

This PR adds 2 methods to the Application which determines if service provider loaded or not.

if ($app->isProviderLoaded(OptionalServiceProvider::class)) {
    // Do something
}

if ($app->isProviderNotLoaded(RequiredServiceProvider::class)) {
    // Throw exception
}

It might be useful in package development when you want to be 100% sure that provider is loaded. Or when you want to load some extra stuff if some optional providers are loaded.

@taylorotwell taylorotwell merged commit b49803e into laravel:7.x Jun 20, 2020
@antonkomarev antonkomarev deleted the add-application-is-provider-loaded-method branch June 20, 2020 08:12
@antonkomarev
Copy link
Contributor Author

antonkomarev commented Jun 20, 2020

Only one method was accepted and it was renamed, here is how it will look like:

if ($app->providerIsLoaded(OptionalServiceProvider::class)) {
    // Do something
}

if (! $app->providerIsLoaded(RequiredServiceProvider::class)) {
    // Throw exception
}

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