# php-di/php-di

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/php-di-php-di).**

2,773 stars · 322 forks · PHP · MIT

## Links

- GitHub: https://github.com/PHP-DI/PHP-DI
- Homepage: https://php-di.org
- awesome-repositories: https://awesome-repositories.com/repository/php-di-php-di.md

## Topics

`container-interop` `dependency-injection` `ioc` `php` `psr-11`

## Description

PHP-DI is an inversion of control container designed to manage object lifecycles and dependency resolution within PHP applications. It functions as a centralized registry that automates the wiring of components, allowing for the decoupling of services from their concrete implementations.

The library distinguishes itself by utilizing reflection to inspect class constructor signatures, enabling automatic dependency injection without requiring manual configuration for standard scenarios. It supports recursive resolution of dependency graphs and provides mechanisms for lazy object instantiation, which defers the creation of heavy services until they are accessed.

The framework facilitates modular application architecture through configuration composition, allowing developers to merge and override service definitions across multiple files. It also supports native code configuration, which ensures that service mappings remain compatible with standard static analysis tools, editor auto-completion, and refactoring workflows. Additionally, the container provides capabilities for dynamic function execution, where dependencies are automatically resolved and injected into callables at runtime.

## Tags

### DevOps & Infrastructure

- [Dependency Injection Containers](https://awesome-repositories.com/f/devops-infrastructure/dependency-management/dependency-injection-containers.md) — Manages object instantiation and dependency resolution by inspecting type hints and configuration files in applications.

### Part of an Awesome List

- [Reflection-Based Dependency Resolution](https://awesome-repositories.com/f/awesome-lists/devtools/runtime-reflection/reflection-based-dependency-resolution.md) — Inspects class constructor signatures at runtime to automatically identify and instantiate required dependencies without explicit configuration.

### Software Engineering & Architecture

- [Dependency Injection Frameworks](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-frameworks.md) — Manages object lifecycles and class dependencies in applications by automatically resolving constructor parameters and service requirements at runtime.
- [Automatic Constructor Injection](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-providers/automatic-constructor-injection.md) — Performs automatic dependency injection by resolving class constructor parameters through type-hint inspection. ([source](https://php-di.org/))
- [Inversion-of-Control Containers](https://awesome-repositories.com/f/software-engineering-architecture/inversion-of-control-containers.md) — Automates the lifecycle and wiring of application objects to simplify complex dependency graphs.
- [Custom Object Instantiation](https://awesome-repositories.com/f/software-engineering-architecture/custom-object-instantiation.md) — Provides lazy object instantiation using a factory pattern that resolves missing constructor dependencies only when they are needed. ([source](https://php-di.org/))
- [Callable Wiring](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-containers/callable-wiring.md) — Provides mechanisms for binding container providers directly to functions or methods to enable automatic dependency injection at runtime.
- [Modular Configuration Composition](https://awesome-repositories.com/f/software-engineering-architecture/modular-configuration-composition.md) — Supports merging multiple configuration files and overriding existing definitions to extend or replace service registrations within complex architectures. ([source](https://php-di.org/))
- [Native Code Configurations](https://awesome-repositories.com/f/software-engineering-architecture/native-code-configurations.md) — Allows defining dependency mappings using standard language syntax to gain access to editor features like auto-completion and static analysis. ([source](https://php-di.org/))
- [Recursive Dependency Resolution](https://awesome-repositories.com/f/software-engineering-architecture/recursive-dependency-resolution.md) — Traverses the dependency graph by resolving nested requirements until all objects in the chain are fully instantiated.
- [Service Locators](https://awesome-repositories.com/f/software-engineering-architecture/service-locators.md) — Provides a registry for centralized access to application services and objects to decouple components from their concrete implementations.
- [Modular Application Architectures](https://awesome-repositories.com/f/software-engineering-architecture/software-architecture/architectural-patterns/layering-presentation/application-layer-architectures/application-architecture-patterns/modular-application-architectures.md) — Facilitates modular application architecture by composing multiple configuration files to override or extend service definitions across modules.

### Development Tools & Productivity

- [Configuration Builders](https://awesome-repositories.com/f/development-tools-productivity/task-execution/execution-policies/fluent-builders/configuration-builders.md) — Offers a chainable interface for defining service mappings that allows developers to override or extend definitions through modular configuration.

### Programming Languages & Runtimes

- [Lazy Loading](https://awesome-repositories.com/f/programming-languages-runtimes/dynamic-class-creation/class-loading-mechanisms/lazy-loading.md) — Defers the instantiation of heavy objects by injecting lightweight placeholders that trigger actual creation only upon first access.
- [Dynamic Method Invokers](https://awesome-repositories.com/f/programming-languages-runtimes/dynamic-method-invokers.md) — Invokes callables and methods by automatically injecting required dependencies from a central registry to simplify complex logic.
