mnapoli/php-di
PHP-DI is a practical, feature-rich dependency injection container for PHP. It offers autowiring, constructor injection, flexible definitions, lazy dependencies, and PSR-11 compatibility, helping you build cleaner, more testable applications with minimal configuration and boilerplate.
Illuminate\Container coupling — for reuse in CLI tools, queue workers, or a second service — PHP-DI is the concrete target abstraction. Autowiring plus constructor injection makes that extraction incremental rather than a rewrite.illuminate/container is a leaky choice; PHP-DI (or PSR-11 generally) keeps the dependency surface honest and portable.Adopt when:
Look elsewhere when:
For executives: PHP-DI is a free, MIT-licensed dependency injection container for PHP — the wiring layer that decides which object gets which collaborators. It is a well-known, mature piece of infrastructure, not a bet on an emerging technology. We are not recommending it as a wholesale change to our Laravel application, where the framework already provides this capability and a second container would add cost without benefit. The recommendation is narrower: use it where we write PHP outside the framework — internal libraries, CLI tooling, workers, and any component we intend to share across services — so that code stays portable and testable instead of quietly coupled to a framework we may not always use. The decision is low-cost and reversible: MIT license, no vendor lock-in, PSR-11 standard interface, and a small integration surface.
For engineering: Standardize on PHP-DI for framework-independent PHP modules. Constructor injection and autowiring keep service definitions short; explicit definitions handle the scalar and conditional cases autowiring cannot. Enable the compiled container in any request- or job-critical path and benchmark it. Do not introduce it inside the Laravel app kernel — treat it as the boundary tool for extracted code. Note the maintenance risk: the project is essentially single-maintainer with a healthy but narrow release cadence, so pin versions and keep the container behind the PSR-11 interface so a swap stays cheap.
How can I help you explore Laravel packages today?