league/container
league/container is a lightweight PSR-11 dependency injection container for PHP. Define entries, factories, and autowiring-friendly services to manage application dependencies cleanly, with modern PHP support and solid tooling for testing and analysis.
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?