league/container
PSR-11–compliant dependency injection container from The PHP League. Register services, factories and shared instances, then resolve dependencies with autowiring support. Modern PHP (8.3+) with full docs, tests, and MIT license.
OnDefineEvent, BeforeResolveEvent, DefinitionResolvedEvent, ServiceResolvedEventforType(), forTag(), forId(), where()Container::listen() for registering filtered event listenersContainer::afterResolve() convenience method as a drop-in replacement for inflector()EventDispatcher::hasListenersFor() to check whether listeners exist for a given event typeDefinitionInterface::getTags() for retrieving tags from definitionsContainer::getDelegate(string $class) to retrieve a registered delegate container by typeDefinition::resolveClass() now throws ContainerException with actionable guidance when a class has unsatisfied constructor dependencies, instead of a raw ArgumentCountErrorContainer::inflector() - use Container::afterResolve() or the event system instead. Will be removed in v6.0.DefinitionContainerInterface no longer extends EventAwareContainerInterface (removed)'shared' tag automatically via addTag('shared')EventAwareContainerInterface - the event system is provided by EventAwareTrait on the concrete Container class, not as an interface contract#[Inject] and #[Resolve] attributes.
>=7.2psr/container to ^2.0.0Container::shared convenience method is now explicit Container::addShared method$shared from Container::add, use Container::addSharedServiceProviderInterface now defines return typesprovides method rather than relying on a class property.psr/container ^2.0.0 as the interface cannot be reconciled between versionsregister call. @pcoutinhoReflectionContainer::call on arrow functions.$new argument when getting tagged definitions.{set,get}LeagueContainer methods added to ContainerAwareTrait as a temporary measure until next major release when this can be properly addressed, less hinting of Psr\Container\ContainerInterfacesetConcrete not re-resolving class on when overriding (@jleeothon){set|get}Concrete to definitions to allow for better use of extend.share proxy method that was mistakenly removed in previous major release.defaultToShared method.ReflectionContainer to cache resolutions and pull from cache for following calls.ReflectionContainer converts class name in array callable to object.RawArgument.RawArgument objects as first class dependencies.Container::get.Container::extend would not return a shared definition to extend.ServiceProvider functionality to allow cleaner resolving of complex dependencies.Inflector functionality to allow for manipulation of resolved objects of a specific type.ContainerAwareTrait now returns self ($this).Container::call functionality.ContainerAwareTrait to provide functionality from ContainerAwareInterface.>=8.1psr/container ^2.0.0BootableServiceProviderInterface for eagerly loaded service providers.RawArgument to ensure scalars are not resolved from the container but seen as an argument.Container::share replaces singleton functionality to improve understanding.ReflectionContainer handling all reflection based functionality.Container::call now proxies to ReflectionContainer::call and handles argument resolution in a much more efficient way.isRegisteredCallable method to public API.call now accepts named arguments at runtime.How can I help you explore Laravel packages today?