psr-discovery/container-implementations
Auto-discovers an available PSR-11 container at runtime by checking for well-known implementations and returning the first match. Ideal for SDKs/libraries that want PSR-11 support without hard dependencies or user configuration.
This package provides PSR-11 container implementations (e.g., PsrContainer) for Laravel applications, enabling dependency injection and service container interoperability. To get started:
composer require psr-discovery/container-implementations
PsrContainer facade or bind it to Laravel's container:
use Psr\Container\ContainerInterface;
use PsrDiscovery\ContainerImplementations\PsrContainer;
// Bind the PSR-11 container to Laravel's container
$this->app->bind(ContainerInterface::class, function ($app) {
return new PsrContainer($app);
});
ContainerInterface:
$container = app(ContainerInterface::class);
$service = $container->get(MyService::class);
Service Resolution:
ContainerInterface.$service = PsrContainer::get(MyService::class);
Integration with PSR-15 Middleware:
Psr\Http\Message\ServerRequestHandlerInterface) in Laravel applications.Testing:
$container = new PsrContainer();
$container->set(MyService::class, $mockService);
ContainerInterface:
public function __construct(private ContainerInterface $container) {}
$this->app->singleton(ContainerInterface::class, function ($app) {
return new PsrContainer($app);
});
^11.0. If you're on Laravel 10.x, verify compatibility or pin the package version to ^1.1.1.app()->bound(MyService::class) to check bindings.PsrContainer to add custom logic (e.g., automatic service registration):
class CustomPsrContainer extends PsrContainer {
public function __construct($laravelContainer) {
parent::__construct($laravelContainer);
$this->registerAutomaticBindings();
}
}
psr/http-server-middleware to resolve middleware via the PSR-11 container.^1.1.1 in composer.json:
"psr-discovery/container-implementations": "^1.1.1"
How can I help you explore Laravel packages today?