PHPackages                             ph-7/dependency-injection-container - 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. ph-7/dependency-injection-container

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

ph-7/dependency-injection-container
===================================

Simple PHP 7.1+ Dependency Injection Container (DIC) Library.

1.0.4(6y ago)12514GPL-3.0-or-laterPHPPHP &gt;=7.1.0CI failing

Since Sep 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/pH-7/Simple-PH-DIC)[ Packagist](https://packagist.org/packages/ph-7/dependency-injection-container)[ Docs](https://github.com/pH-7/dependency-injection-container)[ RSS](/packages/ph-7-dependency-injection-container/feed)WikiDiscussions master Synced yesterday

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

P.H.'s Dependency Injection Container Library
=============================================

[](#phs-dependency-injection-container-library)

[![PHP Dependency Injection Container](dependency-injection.svg)](dependency-injection.svg)

Summary ⏳
---------

[](#summary-)

The "P.H.'s DIC" is a simple and lightweight PHP 7.1+ **Dependency Injection Container**'s library which lets you manage your dependencies easily for your next great project 🎉

Requirements ⚙
--------------

[](#requirements-)

- 🐘 [PHP 7.1](http://php.net/releases/7_1_0.php) or newer
- 🎻 [Composer](https://getcomposer.org)

Installation 📓
--------------

[](#installation-)

```
composer require ph-7/dependency-injection-container
```

Usage 🎮
-------

[](#usage-)

Register your new DIC as below (FYI, for this example I use the [Symfony's HttpFoundation](https://packagist.org/packages/symfony/http-foundation) Request).

For the first example, let's create your provider class with an [anonymous class](http://php.net/manual/en/language.oop5.anonymous.php) that implements the `\PierreHenry\Container\Providable` interface.

```
use PierreHenry\Container\Container;
use PierreHenry\Container\Providable;
use Symfony\Component\HttpFoundation\Request;

$container = new Container();

// Register your container
$container->register(
    'example.symfony.httprequest',
    new class implements Providable
    {
        public function getService(): Request
        {
            return Request::createFromGlobals();
        }
    }
);

// Retrieve the container
$httpRequest = $container->get('example.symfony.httprequest');

// Use it
$request = $httpRequest->request; // $_POST body params
if ($request->get('get_var')) {
    echo '$_POST["get var"] exists';
} else {
    echo '"get_var" has not been requested';
}
```

### Another Example... 🎯

[](#another-example-)

```
use DateTime;
use DateTimeZone;
use PierreHenry\Container\Container;
use PierreHenry\Container\Providable;

$container = new Container();
$container->register(
    'stubs.date.datetime',
    new class implements Providable
    {
        public function getService(): DateTime
        {
            return new DateTime('now', new DateTimeZone('America/Chicago'));
        }
    }
);

// Retrieve the container
$date = $container->get('stubs.date.datetime');

// Use it
echo $date->format('m-d-Y H:i:s');
```

Inspired By... 🧠
----------------

[](#inspired-by-)

This project is highly inspired by my [DIC](https://github.com/Lifyzer/Lifyzer-WebApp-CMS/tree/master/Server/Core/Container) I built for another [side-project](https://lifyzer.com).

...Who Am I...? 🤔
-----------------

[](#who-am-i-)

[![Pierre-Henry Soria](https://avatars0.githubusercontent.com/u/1325411?s=200)](http://pierrehenry.be "My personal website :-)")

Hi there! 😉 I'm [Pierre-Henry Soria](http://ph7.me), "[PierreHenry.be](http://pierrehenry.be)™": a cool passionate Belgian software engineer 🇧🇪 😃

You can keep in touch with me at *hi {{AT}} ph7 \[\[D0T\]\] me*!

Passion Drives Me! 🚀
--------------------

[](#passion-drives-me-)

Love programming! 😊 Check out other exciting projects I previously did such as **[Lifyzer Healthy Food](https://github.com/Lifyzer)**, which gives lots of details about what you eat and allow you do scan your food items 🌯 Another project I'm proud of is the **[Social Dating WebApp Builder Project](https://github.com/pH7Software/)** I started 8 years ago ☀️

License ⚖
---------

[](#license-)

Under [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.en.html) or later.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~107 days

Total

4

Last Release

2537d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b6d95da236687f1dca4f7d70d60037c70ef217120ea195df23a39a412ba594e0?d=identicon)[ph-7](/maintainers/ph-7)

---

Top Contributors

[![pH-7](https://avatars.githubusercontent.com/u/1325411?v=4)](https://github.com/pH-7 "pH-7 (34 commits)")

---

Tags

clean-architectureclean-codeclean-phpcontainerdependecy-injectiondependency-injectiondependency-injection-containerdependency-injection-container-phpdependency-injection-frameworkdidicdic-phpphpphp-71php71programmingcontainerinjectiondependency-injectiondidic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ph-7-dependency-injection-container/health.svg)

```
[![Health](https://phpackages.com/badges/ph-7-dependency-injection-container/health.svg)](https://phpackages.com/packages/ph-7-dependency-injection-container)
```

###  Alternatives

[league/container

A fast and intuitive dependency injection container.

86892.2M397](/packages/league-container)[laminas/laminas-servicemanager

Factory-Driven Dependency Injection Container

15857.5M782](/packages/laminas-laminas-servicemanager)[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)[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)[miladrahimi/phpcontainer

Dependency injection (IoC) container for PHP projects

1323.5k2](/packages/miladrahimi-phpcontainer)

PHPackages © 2026

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