league/container
A fast and intuitive dependency injection container.
5.2.0
98M downloads/mo
#438 most downloaded on Packagist
thephpleague/container
What this package is like to depend on
Last release 5 months ago
19 Mar 2026
Ships unpredictably
gaps range from 2 weeks to 2.3 years
Nearly every release is documented
notes for 42 of 46 stable releases
Nothing withdrawn
no release was ever pulled
12 years old
46 releases · first in 2015
1 release in the last 12 months
see the full history below
Release timeline
46 releases · Jan 2015 to Mar 2026Releases
latest 46-
5.2.019 Mar 2026Release notes
Open source →5.2.0
Added
- Event system for hooking into the container lifecycle
- Four event types:
OnDefineEvent,BeforeResolveEvent,DefinitionResolvedEvent,ServiceResolvedEvent - Fluent filtering API:
forType(),forTag(),forId(),where() Container::listen()for registering filtered event listenersContainer::afterResolve()convenience method as a drop-in replacement forinflector()- Lazy event dispatch: events are only created when listeners are registered for that event type
EventDispatcher::hasListenersFor()to check whether listeners exist for a given event typeDefinitionInterface::getTags()for retrieving tags from definitions- Docs: https://container.thephpleague.com/5.x/events/
- Four event types:
Container::getDelegate(string $class)to retrieve a registered delegate container by type
Fixed
- Interface-to-concrete definitions now correctly resolve through the concrete's own registered definition instead of bypassing it via direct reflection (#275, #278)
Definition::resolveClass()now throwsContainerExceptionwith actionable guidance when a class has unsatisfied constructor dependencies, instead of a rawArgumentCountError
Deprecated
Container::inflector()- useContainer::afterResolve()or the event system instead. Will be removed in v6.0.
Changed
DefinitionContainerInterfaceno longer extendsEventAwareContainerInterface(removed)- Shared definitions now receive a
'shared'tag automatically viaaddTag('shared')
Removed
EventAwareContainerInterface- the event system is provided byEventAwareTraiton the concreteContainerclass, not as an interface contract
Release notes
Open source →Added
- Event system for hooking into the container lifecycle
- Four event types:
OnDefineEvent,BeforeResolveEvent,DefinitionResolvedEvent,ServiceResolvedEvent - Fluent filtering API:
forType(),forTag(),forId(),where() Container::listen()for registering filtered event listenersContainer::afterResolve()convenience method as a drop-in replacement forinflector()- Lazy event dispatch: events are only created when listeners are registered for that event type
EventDispatcher::hasListenersFor()to check whether listeners exist for a given event typeDefinitionInterface::getTags()for retrieving tags from definitions- Docs: https://container.thephpleague.com/5.x/events/
- Four event types:
Container::getDelegate(string $class)to retrieve a registered delegate container by type
Fixed
- Interface-to-concrete definitions now correctly resolve through the concrete's own registered definition instead of bypassing it via direct reflection (#275, #278)
Definition::resolveClass()now throwsContainerExceptionwith actionable guidance when a class has unsatisfied constructor dependencies, instead of a rawArgumentCountError
Deprecated
Container::inflector()- useContainer::afterResolve()or the event system instead. Will be removed in v6.0.
Changed
DefinitionContainerInterfaceno longer extendsEventAwareContainerInterface(removed)- Shared definitions now receive a
'shared'tag automatically viaaddTag('shared')
Removed
EventAwareContainerInterface- the event system is provided byEventAwareTraiton the concreteContainerclass, not as an interface contract
- Event system for hooking into the container lifecycle
-
5.1.028 May 2025Release notes
Open source →5.1.0
Added
- Attribute based resolution for dependencies using
#[Inject]and#[Resolve]attributes. - Support for PHPUnit 12 (@ADmad)
- Explicit non-support for auto-wiring union types.
Changed
- Small internal changes for stricter static analysis and type safety. (@ADmad)
Release notes
Open source →Added
- Attribute based resolution for dependencies using
#[Inject]and#[Resolve]attributes. - Support for PHPUnit 12 (@ADmad)
- Explicit non-support for auto-wiring union types.
Changed
- Small internal changes for stricter static analysis and type safety. (@ADmad)
5.0.1
Fixed
- Fixed a small unreachable code bug
- Attribute based resolution for dependencies using
-
5.0.127 Mar 2025Release notes
Open source →5.0.1
Fixed
- Fixed a small unreachable code bug
5.0.0
Added
- Ability to overwrite a definition within the container, disabled by default
Changed
- PHP requirement now
>=8.1 - General language modernisation
- General prep for future updates and container compilation
-
5.0.027 Mar 2025Release notes
Open source →Added
- Ability to overwrite a definition within the container, disabled by default
Changed
- PHP requirement now
>=8.1 - General language modernisation
- General prep for future updates and container compilation
Release notes
Open source →Added
- Ability to overwrite a definition within the container, disabled by default
Changed
-
PHP requirement now >=8.1
-
General language modernisation
-
General prep for future updates and container compilation
Assets 2 Loading
Uh oh!
There was an error while loading. Please reload this page .
👍 1 dragomano reacted with thumbs up emoji All reactions
- 👍 1 reaction
1 person reacted
-
4.2.520 May 2025Nothing published for this version
-
4.2.410 Nov 2024Release notes
Open source →4.2.4
Fixed
- Now properly handle string based fully qualified class names in with preceding slashes. (@M1ke)
Release notes
Open source →Fixed
- Now properly handle string based fully qualified class names in with preceding slashes. (@M1ke)
-
4.2.323 Oct 2024 -
4.2.213 Mar 2024Nothing published for this version
-
4.2.113 Mar 2024Release notes
Open source →Fixed
- Remove an unnecessary conditional in ServiceProviderAggregate. (@SubhanSh)
- Fixed an infinite loop in resolving definitions. (@arai-ta)
-
4.2.016 Nov 2021 -
4.1.226 Jul 2021Release notes
Open source →Fixed
- Fix bug that was causing an error on inflection due to introduced type hint.
-
4.1.109 Jul 2021 -
4.1.009 Jul 2021 -
4.0.009 Jul 2021Release notes
Open source →Added
- New definition interface that extends psr/container
- Literal and resolvable argument wrappers for better explicitness in definitions
Changed
- PHP requirement now
>=7.2 - Updated
psr/containerto ^2.0.0 Container::sharedconvenience method is now explicitContainer::addSharedmethod- Removed third argument
$sharedfromContainer::add, useContainer::addShared ServiceProviderInterfacenow defines return types- Service providers now require implementation of a
providesmethod rather than relying on a class property.
-
3.4.109 Jul 2021Release notes
Open source →Added
- Way to handle non-public controllers safely (@beryllium)
- PHPUnit ^7.0 for PHP versions that support it (@beryllium)
-
3.4.009 Jul 2021Release notes
Open source →Removed
- Support for
psr/container^2.0.0 as the interface cannot be reconciled between versions
- Support for
-
3.3.516 Mar 2021 -
3.3.422 Feb 2021Release notes
Open source →Fixed
- Fixed an issue that caused a recursive
registercall. @pcoutinho - Fixed a return type declaration. @orbex
- Fixed an issue that caused a recursive
-
3.3.328 Sep 2020Release notes
Open source →Fixed
- Fixed bug relating to
ReflectionContainer::callon arrow functions.
- Fixed bug relating to
-
3.3.226 Sep 2020Release notes
Open source →Added
- Experimental support for PHP 8.
Fixed
- Fix issue when preventing reflection from using default value for arguments.
-
3.3.118 May 2020 -
3.3.030 Jun 2019Release notes
Open source →Added
- Support for PHP 7.3
{set,get}LeagueContainermethods added to ContainerAwareTrait as a temporary measure until next major release when this can be properly addressed, less hinting ofPsr\Container\ContainerInterface
Changed
- Various internal code improvements
Fixed
- Fix for
setConcretenot re-resolving class on when overriding (@jleeothon) - Fix stack overflow error incase a service provider lies about providing a specific service (@azjezz)
- Fix issue where providers may be aggregated multiple times (@bwg)
- Various documentation fixes
-
3.2.228 Sep 2018Release notes
Open source →Fixed
- Fixed issue that prevented service providers from registering if a previous one in the aggregate was already registered.
-
3.2.121 Sep 2018Release notes
Open source →Fixed
- Fixed issue where all service providers were registered regardless of whether they need to be.
-
3.2.013 Aug 2018Release notes
Open source →Added
- Added ability to add definition as not shared when container is set to default to shared.
- Added
{set|get}Concreteto definitions to allow for better use ofextend.
-
3.1.012 Aug 2018Release notes
Open source →Added
- Re-added the
shareproxy method that was mistakenly removed in previous major release. - Added ability to set Container to "share" by default using
defaultToSharedmethod. - Added ability for
ReflectionContainerto cache resolutions and pull from cache for following calls.
- Re-added the
-
3.0.125 Jul 2018 -
3.0.023 Jul 2018Release notes
Open source →Added
- Service providers can now be pulled from the container if they are registered.
- Definition logic now handled by aggregate for better separation.
- Now able to add tags to a definition to return an array of items containing that tag.
Changed
- Updated minimum PHP requirements to 7.0.
- Now depend directly on PSR-11 interfaces, including providing PSR-11 exceptions.
- Refactored inflector logic to accept type on construction and use generator to iterate.
- Refactored service provider logic with better separation and performance.
- Merged service provider signature logic in to one interface and abstract.
- Heavily simplified definition logic providing more control to user.
-
2.5.022 Feb 2021Nothing published for this version
-
2.4.110 May 2017Release notes
Open source →Fixed
- Ensures
ReflectionContainerconverts class name in array callable to object.
- Ensures
-
2.4.006 Mar 2017Release notes
Open source →Changed
- Can now wrap shared objects as
RawArgument. - Ability to override shared items.
Fixed
- Booleans now recognised as accepted values.
- Various docblock fixes.
- Unused imports removed.
- Unreachable arguments no longer passed.
- Can now wrap shared objects as
-
2.3.017 Feb 2017 -
2.2.017 Mar 2016Release notes
Open source →Changed
- Service providers can now be added multiple times by giving them a signature.
-
2.1.015 Mar 2016Release notes
Open source →Added
- Allow resolving of
RawArgumentobjects as first class dependencies.
Changed
- Unnecessary recursion removed from
Container::get.
- Allow resolving of
-
2.0.307 Sep 2015Release notes
Open source →Fixed
- Bug where delegating container was not passed to delegate when needed.
- Bug where
Container::extendwould not return a shared definition to extend.
-
2.0.203 Sep 2015Release notes
Open source →Fixed
- Bug introduced in 2.0.1 where shared definitions registered via a service provider would never be returned as shared.
-
2.0.102 Sep 2015 -
2.0.002 Sep 2015Release notes
Open source →Added
- Now implementation of the container-interop project.
BootableServiceProviderInterfacefor eagerly loaded service providers.- Delegate container functionality.
RawArgumentto ensure scalars are not resolved from the container but seen as an argument.
Altered
- Refactor of definition functionality.
Container::sharereplacessingletonfunctionality to improve understanding.- Auto wiring is now disabled by default.
- Auto wiring abstracted to be a delegate container
ReflectionContainerhandling all reflection based functionality. - Inflection functionality abstracted to an aggregate.
- Service provider functionality abstracted to an aggregate.
- Much bloat removed.
Container::callnow proxies toReflectionContainer::calland handles argument resolution in a much more efficient way.
Removed
- Ability to register invokables, this functionality added a layer of complexity too large for the problem it solved.
- Container no longer accepts a configuration array, this functionality will now be provided by an external service provider package.
-
1.3.205 Apr 2015Nothing published for this version
-
1.3.121 Feb 2015Release notes
Open source →Fixed
- Fixed bug where arbitrary values were attempted to be resolved as classes.
-
1.3.009 Feb 2015Release notes
Open source →Added
- Added
ServiceProviderfunctionality to allow cleaner resolving of complex dependencies. - Added
Inflectorfunctionality to allow for manipulation of resolved objects of a specific type. - Improvements to DRY throughout the package.
Fixed
- Setter in
ContainerAwareTraitnow returns self ($this).
- Added
-
1.2.129 Jan 2015 -
1.2.013 Jan 2015Release notes
Open source →Added
- Improvements to
Container::callfunctionality.
Fixed
- General code tidy.
- Improvements to test suite.
- Improvements to
-
1.1.113 Jan 2015 -
1.1.012 Jan 2015Release notes
Open source →Added
- Addition of
ContainerAwareTraitto provide functionality fromContainerAwareInterface.
- Addition of
-
1.0.012 Jan 2015