PHPackages                             kanian/containerx - 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. kanian/containerx

ActiveLibrary[Framework](/categories/framework)

kanian/containerx
=================

A simple PHP DI container

1.5.1(7y ago)4302[1 issues](https://github.com/kanian/containerx/issues)MITPHP

Since Feb 11Pushed 7y ago1 watchersCompare

[ Source](https://github.com/kanian/containerx)[ Packagist](https://packagist.org/packages/kanian/containerx)[ RSS](/packages/kanian-containerx/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (3)Versions (10)Used By (0)

ContainerX
==========

[](#containerx)

ContainerX is a little PHP dependency injection container.

Installation
============

[](#installation)

```
$ composer require kanian/containerx
```

Usage
=====

[](#usage)

Let:

The **Car** class be:

```
class Car {
	protected $driver;
    public function __construct(Driver $driver)
    {
    	$this -> driver = $driver;
    }
    \\\ ... more car code
}
```

And the **HumanDriver** class be:

```
class HumanDriver implements Driver {
  public function drive()
  {
  	\\\ ... some driving code
  }
}
```

We can use:

Container functionalities as object methods
-------------------------------------------

[](#container-functionalities-as-object-methods)

In order to access the functionalities of the container as object methods:

```
use Kanian\ContainerX\Container;

$container = new Container();
$container->set('chauffeur', function($c){ return new HumanDriver;});
$container->set('limo', function($c){ return new Car($c->get('chauffeur'));});

$limo = $container->get('limo');
```

We have used anonymous functions has factories. Moreover, We could simply register the dependencies we need and let the container instantiate them:

```
use Kanian\ContainerX\Container;
$container = new Container();
$container->set('chauffeur',HumanDriver::class);
$container->set('limo',Car::class);
$limo = $container->get('limo');
```

The container will know how to construct a Car instance for us.

Alternatively, we can use:

Container functionalities through the ArrayAccess Interface
-----------------------------------------------------------

[](#container-functionalities-through-the-arrayaccess-interface)

For example, we can achieve factory based registration by using the **Kanian\\Container\\ContainerX** class, which implements the ArrayAccess interface.

```
use Kanian\ContainerX\ContainerX;

$container = new ContainerX();
$container['chauffeur'] =  HumanDriver::class;
$container['limo'] = Car::class;

$limo = $container['limo'];
```

Accessing a dependency as a Singleton
=====================================

[](#accessing-a-dependency-as-a-singleton)

In order to ensure that there is receive only one copy of a dependency in the system at a time, you will use the

```
singletonize
```

method. like this:

```
$container->singletonize('limo', Car::class);
$limo = $container['limo'];
```

Now you will always get the same instance of Car, but with different instances of HumanDriver..

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

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 ~5 days

Total

8

Last Release

2612d ago

### Community

Maintainers

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

---

Top Contributors

[![kanian](https://avatars.githubusercontent.com/u/626923?v=4)](https://github.com/kanian "kanian (56 commits)")

---

Tags

phpdi container

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kanian-containerx/health.svg)

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

###  Alternatives

[phalcon/phalcon

Phalcon Framework

2421.5k1](/packages/phalcon-phalcon)[lagdo/symfony-facades

Call Symfony services using facades.

1868.7k](/packages/lagdo-symfony-facades)

PHPackages © 2026

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