You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a ServiceProvider implements the DeferrableProvider interface, it is registered only when one of the services declared in its provides() method is built.
My issue is to extend one of this services in a DeferrableProvider provided by my package. If I add the service name in the "provides" list, it replaces the original CoreServiceProvider. So I can't extend it. I could only redefine it with $app->singleton().
class MyPackageServiceProvider extends ServiceProvider implements DeferrableProvider
{
publicfunctionregister()
{
$this->app->extends(CoreInterface::class, function (CoreInterface$instance, Container$app) { ... });
// ERROR! The service "CoreInterface" is not instantiable because the CoreServiceProvider is not registered
}
publicfunctionprovides()
{
return [CoreInterface::class];
}
}
If the service name is not in the "provides" list, my provider is never registered.
class MyPackageServiceProvider extends ServiceProvider implements DeferrableProvider
{
publicfunctionregister()
{
$this->app->extends(CoreInterface::class, function (CoreInterface$instance, Container$app) { ... });
// FAILED! This is never registered
}
publicfunctionprovides()
{
return [];
}
}
Partial solution
My current solution is to explicitly call the CoreServiceProvider from MyPackageServiceProvider. But this is not 100% safe as an other package could extend the same service. It would not be registered either.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When a
ServiceProvider
implements theDeferrableProvider
interface, it is registered only when one of the services declared in itsprovides()
method is built.Problem
My issue is to extend one of this services in a
DeferrableProvider
provided by my package. If I add the service name in the "provides" list, it replaces the originalCoreServiceProvider
. So I can't extend it. I could only redefine it with$app->singleton()
.If the service name is not in the "provides" list, my provider is never registered.
Partial solution
My current solution is to explicitly call the
CoreServiceProvider
fromMyPackageServiceProvider
. But this is not 100% safe as an other package could extend the same service. It would not be registered either.Actually implemented in mongodb/laravel-mongodb#3071
Proposition
All the service providers providing a service should be called. Instead of having a single provider per service name, it should be a list:
framework/src/Illuminate/Foundation/ProviderRepository.php
Line 149 in b18f333
And all the associated providers would be registered when the service is built.
Beta Was this translation helpful? Give feedback.
All reactions