PHPackages                             comphp/di - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. comphp/di

Abandoned → [comphp/runtime](/?search=comphp%2Fruntime)ArchivedLibrary[Framework](/categories/framework)

comphp/di
=========

CommonPHP DependencyInjection is a simple, robust dependency injection container for PHP applications. It facilitates the dynamic creation of objects, invocation of methods, function calling, and property population.

v0.2.1(1y ago)664[3 issues](https://github.com/commonphp/di/issues)1MITPHPPHP ^8.3

Since Jul 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/commonphp/di)[ Packagist](https://packagist.org/packages/comphp/di)[ RSS](/packages/comphp-di/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (1)Versions (5)Used By (1)

CommonPHP Dependency Injection
==============================

[](#commonphp-dependency-injection)

`CommonPHP\DependencyInjection` is a simple yet powerful dependency injection (DI) container for PHP applications, enabling the means to dynamically create new objects, invoke methods, call functions and populate properties without having to know the structure of the target directly.

Features
--------

[](#features)

- Constructor and method injection: Instantiate classes and invoke methods with automatic resolution of dependencies.
- Value finder: A support class for the DI process that assists in discovering and managing parameter values during instantiation.
- Handling of circular dependencies: An instantiation stack to prevent issues caused by recursive dependency chains.
- Customizable parameter lookup: Enhance the default lookup process by adding custom lookup hooks.
- Populating object properties: Assign values to an object's properties, handling a variety of visibility and type scenarios.
- Exception handling: A series of specific exceptions to help troubleshoot issues related to DI and instantiation.

Requirements
------------

[](#requirements)

The CommonPHP framework requires PHP 8.3 or newer. This library specifically has the following dependencies:

- PHP's built-in Reflection classes, which are used extensively for instantiating classes, invoking methods, and reading type information.

Installation
------------

[](#installation)

You can install `CommonPHP\DependencyInjection` using [Composer](https://getcomposer.org/):

```
composer require comphp/di
```

Basic Usage
-----------

[](#basic-usage)

### Instantiating Classes

[](#instantiating-classes)

The main component is the `DependencyInjector` class, which is responsible for injecting the passed parameters into a constructor, method or function.

```
