laminas/laminas-di
Dependency injection container for Laminas apps. Supports autowiring, configuration-driven definitions, factories, and runtime instantiation to manage object creation and wiring with minimal boilerplate. Integrates with Laminas ServiceManager patterns and PSR-friendly practices.
Pros:
Illuminate\Container (PSR-11 compatible), enabling a drop-in replacement for manual DI or third-party containers.bind()/singleton() calls for most use cases, improving developer velocity.ClassDefinition improvements in v3.8.0+) and memory efficiency, critical for Laravel’s request lifecycle.Laminas\ServiceManager, enabling hybrid architectures if needed.Cons:
app()->make() already handles this via bind()), but this is intentional and aligns with modern PHP standards.singleton()). Workaround: Use Laravel’s container for shared instances or wrap laminas-di in a decorator.app()->bind() can mitigate this).Illuminate\Container is PSR-11 compatible, so laminas-di can act as a drop-in container backend.laminas-di for autowiring in specific modules (e.g., domain layers) while retaining Laravel’s container for global services.laminas-di for new services/classes, then migrate existing bindings gradually.app()->make() calls remain unchanged; new code leverages autowiring.laminas-di no longer supports v1 (removed in v3.9.1), but Laravel’s container is v2-compatible.laminas-di handles these via exceptions (same as Laravel), but testing is required.ConfigInterface to resolve (Laravel’s bind() can override).singleton() suffice, or is a decorator pattern needed?Mockery/PHPUnit may need adjustments for autowired dependencies.laminas-di alongside Laravel’s container, or replace it entirely? Laravel’s container is actively developed (e.g., v9+ improvements).laminas-di has PSalm integration (v3.11.0+), which may improve static analysis.Illuminate\Container with laminas-di via a custom service provider (e.g., LaminasDiServiceProvider).laminas-di for autowiring in domain layers while keeping Laravel’s container for framework services.laminas-di’s code generators to create factories for Laminas\ServiceManager if needed.laminas-di is not a drop-in replacement for Symfony’s DI.laminas-di autowiring.--debug in Laravel to inspect bindings).bind() calls with laminas-di autowiring for new classes.app()->bind() for shared instances or complex initialization.Illuminate\Container or create a decorator to delegate resolution to laminas-di.$container = new Laminas\Di\DefaultContainer();
$app->bind('container', fn() => $container);
laminas-di’s generators to create factories for Laminas\ServiceManager if hybrid architectures are needed.laminas-di v3.10.0+ (PHP 8.0+), but may require polyfills for deprecated features.laminas-di requires PSR-Container v2 (Laravel’s container is compliant).laminas/laminas-di is listed in composer.json and autoloaded.bind()/singleton() calls to identify shared vs. unshared services.--env=testing to validate container behavior.laminas-di usage.bind() calls mean less maintenance for dependency management.laminas-di could complicate future Laravel upgrades (though unlikely, given Laravel’s stability).laminas-di’s debug tools (e.g., ClassDefinition inspection) or Laravel’s --debug flag.php artisan tinker --debug
$this->app->make(\App\Service::class, ['debug' => true]);
laminas-di has active maintenance (releases every 2–3 months).ClassDefinition instances (if using a custom container).laminas-di is lightweight (~1–2MB overhead), but shared instances (via Laravel’s container) reduce duplication.How can I help you explore Laravel packages today?