PHPackages                             minusfour/phpdicontainer - 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. minusfour/phpdicontainer

ActiveLibrary

minusfour/phpdicontainer
========================

Simple DI Container

v1.0.0(11y ago)017GPL-2.0PHPPHP &gt;=5.3

Since May 17Pushed 11y ago1 watchersCompare

[ Source](https://github.com/MinusFour/phpDIContainer)[ Packagist](https://packagist.org/packages/minusfour/phpdicontainer)[ RSS](/packages/minusfour-phpdicontainer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

phpDIContainer
==============

[](#phpdicontainer)

Very simple Dependency Injector Container.

Installing
==========

[](#installing)

You can install it through composer. Through the CLI:

```
composer require minusfour/phpdicontainer

```

Don't forget to add the autoloader to your bootstrap file:

```
require 'vendor/autoload.php';
```

How to use
==========

[](#how-to-use)

Start by specifying the class namespace:

```
use MinusFour\DIContainer\Container;
use MinusFour\DIContainer\Injector;
```

Instantiate the container.

```
$container = new Container();
```

Register an injector. Assuming class A depends on class B.

```
$container->registerInjector(new Injector('A', function($deps){
    return new A($deps['B']);
}, ['B']));
```

And register the injector dependencies. In this case B.

```
$container->registerInjector(new  Injector('B', function($deps){
    return new A($deps['B']);
}));
```

To resolve a class, all you need to do is:

```
$A = $container->resolve('A');
```

It will instantiate A and inject its dependencies through their injectors.

Note
====

[](#note)

The injector constructor takes three parameters. The first parameter must be the name of the class (or dependency), the third parameter is an array containing a list of dependencies (names must match first parameter). The second parameter is an anonymous function that takes one parameter, the dependencies as an array of objects and is responsible for both instantiation and dependency injection.

The injector implementation borrows from [pimple](http://pimple.sensiolabs.org/) examples, mostly the anonymous function idea.

Exceptions note
===============

[](#exceptions-note)

`$container->resolve()` is responsible for throwing 2 kind of exceptions: `MinusFour\DIContainer\InjectorNotFoundException` and `MinusFour\DIContainer\DependencyUnmetException`. First only occurs if there's no injector for said class, second one is thrown when the container fails to find the injector of the dependency.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

4020d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/edf6b85be4c547cf1c8ab9455dc0928e8a123dc51803677cc399b6775da2530b?d=identicon)[MinusFour](/maintainers/MinusFour)

---

Top Contributors

[![MinusFour](https://avatars.githubusercontent.com/u/8602015?v=4)](https://github.com/MinusFour "MinusFour (6 commits)")

### Embed Badge

![Health badge](/badges/minusfour-phpdicontainer/health.svg)

```
[![Health](https://phpackages.com/badges/minusfour-phpdicontainer/health.svg)](https://phpackages.com/packages/minusfour-phpdicontainer)
```

PHPackages © 2026

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