yiisoft/di
PSR-11 compatible dependency injection container for PHP 8.1+. Supports autowiring plus constructor, method and property injection, aliasing, service providers, delegated/composite containers, circular reference detection, and state reset for long-running workers.
yiisoft/di aligns with PSR-11 standards, ensuring compatibility with modern PHP ecosystems (e.g., Laravel, Symfony). This simplifies future integrations or migrations if the tech stack evolves.Adopt When:
new Database() in classes).Look Elsewhere If:
yiisoft/di can coexist).Pimple or PHP-DI).yiisoft/di supports modern PHP).*"This is a strategic investment in code maintainability and scalability. By adopting yiisoft/di—a lightweight, PSR-11-compliant dependency injection container—we’ll:
*"yiisoft/di gives us:
new UserRepository($db) with $container->get(UserRepository::class), then swap $db for a mock in tests. No more global $db hacks.*
Tradeoff: Slight learning curve for DI patterns (but worth it for large codebases)."*How can I help you explore Laravel packages today?