PHPackages                             mouf/root-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mouf/root-container

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mouf/root-container
===================

This package contains a PHP DI container detector and aggregator. The idea is to have potentially one DI container per composer package and to aggregate all those containers into a 'root' container.

2.0.x-dev(11y ago)1302PHPPHP &gt;=5.4

Since Jan 16Pushed 11y ago16 watchersCompare

[ Source](https://github.com/thecodingmachine/root-container)[ Packagist](https://packagist.org/packages/mouf/root-container)[ Docs](http://mouf-php.com/packages/mouf/root-container)[ RSS](/packages/mouf-root-container/feed)WikiDiscussions 1.0 Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

About RootContainer
===================

[](#about-rootcontainer)

RootContainer is a *facade* for a composite container that aggregates all DI containers detected in the application.

The big picture
---------------

[](#the-big-picture)

The ultimate goal is to allow the application developer to easily create a "root container", that can automatically detect and add containers contained in other packages into a global composite container that can be used by the application.

Compared to the classical way of thinking about a web application, this is a paradigm shift.

**In a "classical" application**, packages added to the application may add new instances to the main and only DI container. This is what SF2 bundles, ZF2 modules or Mouf2 packages are doing.

**Using this approach**, each package provides its own DI container that contains instances. DI containers are added to a global container that is queried.

About this package
------------------

[](#about-this-package)

Detection of other containers is done using the [Container-Installer](http://mouf-php.com/packages/mouf/container-installer)component.

This package is using detected packages and aggregate those into a unique composite container. This container is exposed as a facade.

So basically, using **RootContainer**, you can access ANY instance of ANY container of your application using:

```
$instance = RootContainer::get("instance_name");
```

In the background, `RootContainer` will load the `containers.php` file generated by [Container-Installer](http://mouf-php.com/packages/mouf/container-installer) and instanciate all the containers of the application.

A word of caution
-----------------

[](#a-word-of-caution)

Having an easy to use facade for containers does not allow you to use it all over the place :) Otherwise, you would be using the RootContainer as a service locator, which is considered by most people to be a bad practice (tip: the author of RootContainer thinks it is a bad practice too).

So in a perfect world, the RootContainer should be used once or twice in your application, maybe by the MVC framework you are using, to fetch the controller, and that's it.

That being said, it's always useful to be able to access an instance quickly for testing purposes.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity44

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

Every ~24 days

Total

2

Last Release

4116d ago

Major Versions

1.0.x-dev → 2.0.x-dev2015-02-09

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

---

Top Contributors

[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (12 commits)")

---

Tags

diContainerInterop

### Embed Badge

![Health badge](/badges/mouf-root-container/health.svg)

```
[![Health](https://phpackages.com/badges/mouf-root-container/health.svg)](https://phpackages.com/packages/mouf-root-container)
```

###  Alternatives

[level-2/dice

A minimalist Dependency injection container (DIC) for PHP. Please note: 3.0+ is only compatible with PHP 7.0. The 2.0 branch is compatbile with PHP 5.6.

437730.3k17](/packages/level-2-dice)[hyperf/di

A DI for Hyperf.

182.8M594](/packages/hyperf-di)[marcelog/ding

PHP Dependency Injection based on Spring(tm), with Aspect Oriented Programming, MVC

1202.1k](/packages/marcelog-ding)[x-wp/di

The dependency injection container for WordPress

301.1k10](/packages/x-wp-di)

PHPackages © 2026

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