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
{{ message }}
This repository was archived by the owner on May 16, 2026. It is now read-only.
If a service provider requires that a class be registered as a service, the logical thing is to check for the existence of it in the bootstrap. When calling ->supports(...) the recursion starts as it asks the service manager for the (potentially) non-instantiated instance of the dependant class, at which point it will iterate through service providers and check if the current service provider supports the class - at which point it goes back to the service manager
The current workaround, placed in the ->supports(...) method, is to check if the class name matches any of the dependent service classes and, if so, return false.
We need to find a way to have something similar to the instantiation stack on the DI library, so a specific service provider is never called recursively.
class RecursionTestServiceProvider implements ServiceProviderContract, BootstrapperContract
{
privateServiceManager$serviceManager;
#[\Override] functionbootstrap(ServiceManager$serviceManager): void
{
$this->serviceManager = $serviceManager;
if (!$serviceManager->has(RecursionTestService::class))
{
thrownewException('Why doesn\'t this throw?');
}
// WARNING: This is recursively called
}
#[\Override] publicfunctionsupports(string$className): bool
{
// WARNING: This is recursively calledreturn$this->serviceManager->get(RecursionTestService::class)->supports($className);
}
#[\Override] publicfunctionhandle(string$className, array$parameters = []): object
{
// TODO: Implement handle() method.
}
#[\Override] publicfunctionisSingletonExpected(string$className): bool
{
// TODO: Implement isSingletonExpected() method.
}
}
class RecursionTestService
{
publicfunctionsupports($className): bool
{
// WARNING: This is recursively called
}
}
$serviceManager = newServiceManager();
$serviceManager->providers->registerProvider(RecursionTestServiceProvider::class);;
If a service provider requires that a class be registered as a service, the logical thing is to check for the existence of it in the bootstrap. When calling ->supports(...) the recursion starts as it asks the service manager for the (potentially) non-instantiated instance of the dependant class, at which point it will iterate through service providers and check if the current service provider supports the class - at which point it goes back to the service manager
The current workaround, placed in the ->supports(...) method, is to check if the class name matches any of the dependent service classes and, if so, return false.
We need to find a way to have something similar to the instantiation stack on the DI library, so a specific service provider is never called recursively.