mouf/picotainer
Picotainer is a tiny (24 lines) dependency injection container for PHP, inspired by Pimple and compatible with container-interop/PSR-11. Define entries as closures, support delegate lookup, and retrieve services with a minimalist API.
Illuminate\Container without enforcing a full replacement.$laravelContainer = app();
$picotainer = new Picotainer([], $laravelContainer); // Delegate to Laravel’s container
singleton(), bindIf(), tag(), or facade support). Workarounds require manual implementation.ServiceProvider class assumes the Illuminate\Container interface. Picotainer’s ContainerInterface must be explicitly bridged (e.g., via adapters or wrapper classes).has() or get() methods (e.g., recursive delegate lookups).app()->when()).php artisan container:inspect).dd(app()))?php-di/php-di, aura/di) that offer modern features with similar minimalism?composer require mouf/picotainer
use Mouf\Picotainer\Picotainer;
use Psr\Container\ContainerInterface;
class PicotainerServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton('picotainer', function () {
return new Picotainer([
'my.cli.service' => function (ContainerInterface $container) {
return new MyCliService();
},
]);
});
}
}
use Psr\Container\ContainerInterface;
class MyCommand extends Command
{
protected $picotainer;
public function __construct(ContainerInterface $picotainer)
{
$this->picotainer = $picotainer;
parent::__construct();
}
public function handle()
{
$service = $this->picotainer->get('my.cli.service');
$service->execute();
}
}
$picotainer = app('picotainer');
$picotainer->set('MyRepository', function () {
return new MyRepository(new DBConnection());
});
$laravelContainer = app();
$picotainer = new Picotainer([], $laravelContainer); // Delegate to Laravel’s container
$picotainer->set('my.picotainer.service', function (ContainerInterface $container) {
return new MyService($container->get('shared.dependency'));
});
class LaravelPicotainerAdapter implements ContainerInterface
{
protected $picotainer;
public function __construct(Picotainer $picotainer)
{
$this->picotainer = $picotainer;
}
public function get($id)
{
return $this->picotainer->get($id);
}
public function has($id)
{
return $this->picotainer->has($id);
}
}
Illuminate\Container (Not Recommended):
| Feature | Laravel Container | Picotainer | Workaround |
|---|---|---|---|
| PSR-11 Compliance | ✅ Yes | ✅ Yes | Native support |
How can I help you explore Laravel packages today?