PHPackages                             mouf/interop.symfony.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. mouf/interop.symfony.di

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

mouf/interop.symfony.di
=======================

This package contains an implementation of the Symfony 2 DI container that can be extended using other DI containers (from other frameworks).

v0.2.0(12y ago)131MITPHPPHP &gt;=5.3.3

Since Sep 25Pushed 12y ago11 watchersCompare

[ Source](https://github.com/thecodingmachine/interop.symfony.di)[ Packagist](https://packagist.org/packages/mouf/interop.symfony.di)[ Docs](http://mouf-php.com/packages/mouf/interop.symfony.di)[ RSS](/packages/mouf-interopsymfonydi/feed)WikiDiscussions 2.3 Synced 2d ago

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

Extensible DI container for Symfony2
====================================

[](#extensible-di-container-for-symfony2)

This package contains an `ExtensibleContainer` class that extends the `Container` class of Symfony 2. The extended class will let you add additional dependency injection containers (DIC) to Symfony 2's container.

This means that when you develop a Symfony 2 application, you are no more forced into using Symfony's DIC only. You can now use add any DIC you want!

How does it work?
-----------------

[](#how-does-it-work)

To make this work, you must put the Symfony2 container inside a composite container that will contain other containers. There is a great implementation of a [`CompositeContainer`](https://github.com/jeremeamia/acclimate-container/blob/master/src/CompositeContainer.php)in the [Acclimate](https://github.com/jeremeamia/acclimate-container/) projet.

The typical workflow will look like this:

[![workflow](doc/images/workflow.png)](doc/images/workflow.png)

The router (or any other component) will ask for an instance to the `ExtensibleContainer`. The `ExtensibleContainer`will forward the call to the `CompositeContainer` that will in turn forward the call to any other container in the `CompositeContainer`. To enter the `CompositeContainer`, a container must respect the `ContainerInterface`as defined in the [container-interop project](https://github.com/container-interop/container-interop).

Installation
------------

[](#installation)

The `ExtensibleContainer` is distributed as a [Composer package](https://packagist.org/packages/mouf/interop.symfony.di). You will also typically need Acclimate (for the composite container) and other containers.

```
{
	// Let's replace container-interop as long as the ParentAwareContainerInterface is not adopted:
	"repositories" : [
		{
			"type" : "vcs",
			"url" : "git@github.com:moufmouf/container-interop.git"
		}
	],
	require: {
		... the dependencies to Symfony go here ...
		"mouf/interop.symfony.di" : "2.3.*",
		"acclimate/container" : "~1.0",
		// As long as the ParentAwareContainerInterface is not adopted by container-interop, you need this:
		"container-interop/container-interop" : "dev-parentaware as 1.0.0",
		// You will also need dependencies to the containers you want to use, for instance:
		"mouf/mouf" : "~2.0"
	}
}

```

In your `app/AppKernel.php` file, add these 2 methods:

```
...

class AppKernel extends Kernel {
	...

	/**
	 * Gets the container's base class.
	 * We use this to make Symfony use the ExtensibleContainer.
	 *
	 * @return string
	 */
	protected function getContainerBaseClass()
	{
		return 'Mouf\\Symfony\\Component\\DependencyInjection\\ExtensibleContainer';
	}

	/**
	 * Initializes the service container.
	 *
	 * Use this method to initialize your own DI container and register it
	 * in Symfony DI container.
	 */
	protected function initializeContainer()
	{
		parent::initializeContainer();

		// Here, you can access the Symfony container using $this->container and register
		// your own container in it.

		$compositeContainer = new CompositeContainer();

		// The SF2 container does not implement the ContainerInterface interface
		// Therefore, it needs to be "acclimated".
    	$acclimator = new ContainerAcclimator();
    	$sfContainer = $this->container;
    	$sfContainer->setParentContainer($compositeContainer);
    	$acclimatedSfContainer = $acclimator->acclimate($this->container);

    	$compositeContainer->addContainer($acclimatedSfContainer);

    	// Now, let's add other containers.
    	// They must implement the ContainerInterface (and optionnally the ParentAwareContainerInterface)
    	$compositeContainer->addContainer(MoufManager::getMoufManager());
	}
}
```

Your DI container must respect the [`ContainerInterface` provided by the container-interop project.](https://github.com/container-interop/container-interop)

What DI containers can I plug in Symfony?
-----------------------------------------

[](#what-di-containers-can-i-plug-in-symfony)

Out of the box, you can plug these DI containers, because they respect the `ContainerInterface` interface:

- Mouf2 ()
- PHP-DI 4.1+ ()
- PimpleInterop (, a wrapper around Pimple)

But wait! Thanks to Jeremy Lindblom and its awesome [Acclimate package](https://github.com/jeremeamia/acclimate), you can now take almost any dependency injection container out there, and get an adapter on that container that respects the `ContainerInterface` interface.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

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

Total

3

Last Release

4424d ago

Major Versions

v0.1.0 → 2.3.x-dev2014-04-02

### 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 (6 commits)")

---

Tags

symfonydependency-injectiondiinterop

### Embed Badge

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

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)

PHPackages © 2026

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