Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Di Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. buy for container infrastructure. DI is commodity plumbing. PHP-DI is MIT-licensed, PSR-11 compliant, and mature enough that writing an in-house container is almost never justified. This package closes the question and frees engineering time for differentiated work.
  • Framework-agnostic core extraction. If the roadmap includes pulling domain logic, shared libraries, or a service layer out of 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.
  • Package and library strategy. If we ship SDKs or internal packages consumed by both Laravel and non-Laravel PHP codebases, depending on illuminate/container is a leaky choice; PHP-DI (or PSR-11 generally) keeps the dependency surface honest and portable.
  • Testing and environment substitution. First-class support for definitions, factories, and overrides means test doubles and per-environment wiring are configured, not hacked in. This supports a decision to standardize test bootstrapping across services.
  • Modular monolith / plugin architecture. Definition files and autowiring let us define module boundaries as service-provider-like configuration without a full framework, enabling a decision to keep one deployable while enforcing internal seams.
  • Scope call on framework consolidation. Choosing PHP-DI explicitly declines a full-framework migration for a given service. That is a cheap, reversible architectural bet compared to adopting Symfony or consolidating onto Laravel.

When to Consider This Package

Adopt when:

  • The codebase is plain PHP or framework-light (CLI tools, workers, small services, SDKs) and needs a container at all.
  • We need PSR-11 interoperability so the container can be swapped or composed with another implementation.
  • Autowiring materially reduces boilerplate — constructor-injected services with type-hinted dependencies and few scalar args.
  • We want framework-independent domain code as a stated architectural goal, not an aspiration.
  • The team is small and prefers explicit, readable configuration over annotation-heavy or convention-magic containers.

Look elsewhere when:

  • The product is a conventional Laravel application end to end. Laravel's container already does autowiring, contextual binding, and lifecycle management; adding PHP-DI creates two containers, two resolution paths, and a debugging story nobody wants. The integration cost outweighs the benefit.
  • The stack is Symfony-first — Symfony's DI component with compilation and tags is the native answer.
  • We need heavy AOP, decorators-by-attribute, or compile-time validation at scale; that pushes toward Symfony DI or Ray.Di.
  • Bus factor is a blocker. Effectively a single-maintainer project. Recent releases (Aug 2025) are reassuring, but a critical-path dependency on a one-person package should be paired with a fork-or-replace contingency or constrained to non-critical services.
  • Throughput is the binding constraint and we cannot run the container's compiled/cached mode. Reflection-based resolution in hot paths is a real cost; measure before adopting in latency-sensitive services.
  • Adoption would be speculative — "we might extract services someday" is not a reason. The score here (40/100, opportunity 23/100) signals a solid but niche tool: real value in the right context, low incremental upside if we are already framework-committed.

How to Pitch It (Stakeholders)

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core