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.
Illuminate\Container\Container (PSR-11) is functionally equivalent but lacks some League’s features (e.g., inflectors). Replacing it would require:
AppServiceProvider would need migration to League’s API (e.g., add() instead of bind()).app()->bind() → League’s add() (syntactic shift).singleton() in Laravel vs. implicit in League).make:controller, make:middleware generators, which rely on the container’s internals).app()->when()).php artisan league:convert) be viable?Illuminate\Container\Container in Illuminate/Foundation/Application.add()/addArgument() replaces Laravel’s bind()/extend().app(), singleton(), bindIf() would need wrappers or aliases.Mockery/PHPUnit tests using Laravel’s container would require updates to use League’s API.composer require league/container).AppServiceProvider:
$this->app->delegate(new League\Container\Container());
add() instead of bind()).bootstrap/app.php:
$app = new Illuminate\Foundation\Application(
new League\Container\Container()
);
Psr\Container\ContainerInterface).add()).php-di, symfony/dependency-injection) will work, but Laravel-specific packages (e.g., laravel/tinker) may need updates.| Failure Scenario | Laravel’s Container | League’s Container | Mitigation |
|---|---|---|---|
| Missing binding | BindingResolutionException |
NotFoundException |
Use has() checks or delegate fallbacks. |
| Circular dependencies | CircularDependencyException |
CircularReferenceException |
Refactor or use League’s inflectors. |
| Invalid argument types | Type-hinted resolution | Explicit ResolvableArgument |
Validate inputs early. |
| Container corruption (edge case) | Rare | Rare | Use immutable configurations. |
| PHP 8.3+ compatibility | Supported | Supported | Test on target PHP versions. |
add(), delegate(), inflectors).AppServiceProvider to League.bind() → add(), when() → inflector).How can I help you explore Laravel packages today?