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.
The ReflectionContainer supports two modes, which can be enabled or disabled using the mode property:
ReflectionContainer::AUTO_WIRING — Enables auto wiring (resolving dependencies by type-hint).ReflectionContainer::ATTRIBUTE_RESOLUTION — Enables attribute-based resolution (using attributes like #[Inject] or #[Resolve]).By default, both modes are enabled. You can control them like this:
<?php
use League\Container\ReflectionContainer;
// Enable only auto wiring (disable attribute resolution)
$container->delegate(
new ReflectionContainer(
cacheResolutions: false,
mode: ReflectionContainer::AUTO_WIRING
)
);
// Enable only attribute resolution (disable auto wiring)
$container->delegate(
new ReflectionContainer(
cacheResolutions: false,
mode: ReflectionContainer::ATTRIBUTE_RESOLUTION
)
);
// Enable both (default)
$container->delegate(
new ReflectionContainer()
);
// Change mode at runtime
$reflectionContainer = new ReflectionContainer();
$reflectionContainer->setMode(ReflectionContainer::AUTO_WIRING);
How can I help you explore Laravel packages today?