bnf/di
Lightweight dependency injection container for PHP/Laravel projects. Configure bindings and resolve services automatically with simple, minimal setup—ideal for small apps or packages that need clean inversion of control without a heavy framework.
bnf/di) aligns well with modern PHP/Laravel architectures by enforcing PSR-11 (Container Interface) standards, promoting loose coupling and testability. It can replace Laravel’s built-in container (Illuminate\Container\Container) or coexist as a secondary container for domain-specific services.app.php (container config) can be extended to delegate specific bindings to bnf/di. Example:
$container->bind('App\Services\PaymentService', fn($c) => new PaymentService($c->get('bnf/di')->get('PaymentGateway')));
bnf/di. Requires manual mapping.bnf/di replace Laravel’s container in tests without breaking test suites?HttpKernel or DependencyInjection, this could serve as a lightweight alternative to Symfony’s full DI container.bnf/di via Composer.$di = new \Bnf\Di\Container();
$di->bind('App\Jobs\ProcessOrder', fn($c) => new ProcessOrder($c->get('OrderRepository')));
public function register()
{
$this->app->bind('bnf/di', fn() => new \Bnf\Di\Container());
$this->app->when('App\Services\UserService')->needs('di')->give('bnf/di');
}
bnf/di and overriding Laravel’s bootstrapping (advanced, not recommended unless necessary).app()->makeWith()).bnf/di to mimic Laravel’s API).auth.di, payment.di).Symfony\Cache) can be added to bnf/di for performance-critical paths.bnf/di's has() method to check bindings before resolution.app.php + bnf/di config) risk inconsistency.app()->singleton() or app()->when() won’t work directly. Requires wrappers or manual implementation.bnf/di usage.bnf/di.bnf/di.bnf/di equivalents.| Laravel Feature | bnf/di Equivalent |
|---|---|
app()->singleton() |
$container->singleton() |
| Context binding | Manual binding per context |
How can I help you explore Laravel packages today?