PHPackages                             radutopala/mnapoli-php-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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. radutopala/mnapoli-php-di

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

radutopala/mnapoli-php-di
=========================

PHP-DI is a Container that makes Dependency Injection as practical as possible in PHP

3.0.5(13y ago)068MITPHPPHP &gt;=5.3.0

Since Sep 29Pushed 13y agoCompare

[ Source](https://github.com/radutopala/PHP-DI)[ Packagist](https://packagist.org/packages/radutopala/mnapoli-php-di)[ Docs](http://mnapoli.github.com/PHP-DI/)[ RSS](/packages/radutopala-mnapoli-php-di/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (19)Used By (0)

PHP-DI is a Container that makes [*Dependency Injection*](http://en.wikipedia.org/wiki/Dependency_injection)as practical as possible.

PHP-DI also tries to avoid falling into the trap of the "Service Locator" antipattern and help you do *real* dependency injection.

Features
--------

[](#features)

- Simple to start with
- Supports different configuration alternatives to suit every taste:
    - **Reflection**: zero configuration, intelligent guessing
    - **Annotations**: modern, practical and simple
    - **PHP code**: if you like complete control and auto-completion
    - **PHP array**: allows you to store it in a configuration file
    - **YAML**: elegant and concise
    - **XML** (work in progress): more verbose, but more classic
- **Performances**: supports a large number of Caches
- Offers lazy injection: lazy-loading of dependencies (WIP)
- Supports constructor injection, setter injection and property injection

Usage
-----

[](#usage)

Let's go to the [Getting started guide](doc/getting-started.md)!

And there is a [complete documentation](doc/) waiting for you.

What is dependency injection, and why use PHP-DI
------------------------------------------------

[](#what-is-dependency-injection-and-why-use-php-di)

You can first read the [introduction to dependency injection with an example](doc/example.md).

Dependency injection and DI containers are separate notions, and one should use of a container only if it makes things more practical (which is not always the case depending on the container you use).

PHP-DI is about this: make dependency injection more practical.

### How classic PHP code works

[](#how-classic-php-code-works)

Here is how a code **not** using DI will roughly work:

- Application needs Foo (e.g. a controller), so:
- Application creates Foo
- Application calls Foo
    - Foo needs Bar (e.g. a service), so:
    - Foo creates Bar
    - Foo calls Bar
        - Bar needs Bim (a service, a repository, …), so:
        - Bar creates Bim
        - Bar does something

### How Dependency Injection works

[](#how-dependency-injection-works)

Here is how a code using DI will roughly work:

- Application needs Foo, which needs Bar, which needs Bim, so:
- Application creates Bim
- Application creates Bar and gives it Bim
- Application creates Foo and gives it Bar
- Application calls Foo
    - Foo calls Bar
        - Bar does something

This is the pattern of **Inversion of Control**. The control of the dependencies is **inversed** from one being called to the one calling.

The main advantage: the one at the end of the caller chain is always **you**. So you can control every dependencies: you have a complete control on how your application works. You can replace a dependency by another (one you made for example).

For example that wouldn't be so easy if Library X uses Logger Y and you have to change the code of Library X to make it use your logger Z.

### How code using PHP-DI works

[](#how-code-using-php-di-works)

Now how does a code using PHP-DI works:

- Application needs Foo so:
- Application gets Foo from the Container, so:
    - Container creates Bim
    - Container creates Bar and gives it Bim
    - Container creates Foo and gives it Bar
- Application calls Foo
    - Foo calls Bar
        - Bar does something

In short, PHP-DI takes away all the work of creating and injecting dependencies.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 95.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Recently: every ~5 days

Total

16

Last Release

4766d ago

Major Versions

0.9.0 → 1.0.02012-10-06

1.1.0 → 2.0.02012-12-05

2.1.0 → 3.0.02013-04-23

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/647137?v=4)[Radu Topala](/maintainers/radutopala)[@radutopala](https://github.com/radutopala)

---

Top Contributors

[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (284 commits)")[![domu1de](https://avatars.githubusercontent.com/u/1790055?v=4)](https://github.com/domu1de "domu1de (8 commits)")[![cboden](https://avatars.githubusercontent.com/u/617694?v=4)](https://github.com/cboden "cboden (2 commits)")[![Potherca](https://avatars.githubusercontent.com/u/195757?v=4)](https://github.com/Potherca "Potherca (2 commits)")[![radutopala](https://avatars.githubusercontent.com/u/647137?v=4)](https://github.com/radutopala "radutopala (2 commits)")

---

Tags

containerdependency-injectiondi

### Embed Badge

![Health badge](/badges/radutopala-mnapoli-php-di/health.svg)

```
[![Health](https://phpackages.com/badges/radutopala-mnapoli-php-di/health.svg)](https://phpackages.com/packages/radutopala-mnapoli-php-di)
```

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k53.2M1.2k](/packages/php-di-php-di)[aura/di

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

352982.2k60](/packages/aura-di)[mrclay/props-dic

Props is a simple DI container that allows retrieving values via custom property and method names

3512.4M3](/packages/mrclay-props-dic)[slince/di

A flexible dependency injection container

20268.4k6](/packages/slince-di)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2859.2k2](/packages/capsule-di)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
