Extensible DI container for Symfony2

Overview

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?

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 in the Acclimate projet.

The typical workflow will look like this:

workflow

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.

Installation

The ExtensibleContainer is distributed as a Composer package. 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" : "[email protected]: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:

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()); } }">
...

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.

What DI containers can I plug in Symfony?

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

But wait! Thanks to Jeremy Lindblom and its awesome Acclimate package, you can now take almost any dependency injection container out there, and get an adapter on that container that respects the ContainerInterface interface.

You might also like...
A Symfony2 bundle that integrates Select2 as a drop-in replacement for a standard entity field on a Symfony form.
A Symfony2 bundle that integrates Select2 as a drop-in replacement for a standard entity field on a Symfony form.

select2entity-bundle Introduction This is a Symfony bundle which enables the popular Select2 component to be used as a drop-in replacement for a stand

Symfony2 Bundle for Doctrine Cache

DoctrineCacheBundle Symfony Bundle for Doctrine Cache. Master: Master: Deprecation warning This bundle is abandoned and will no longer be updated. If

A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!

CLIFramework CLIFramework is a command-line application framework, for building flexiable, simple command-line applications. Commands and Subcommands

Guzzle, an extensible PHP HTTP client
Guzzle, an extensible PHP HTTP client

Guzzle, PHP HTTP client Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Simple interf

Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.
Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.

league/commonmark league/commonmark is a highly-extensible PHP Markdown parser created by Colin O'Dell which supports the full CommonMark spec and Git

A super fast, highly extensible markdown parser for PHP

A super fast, highly extensible markdown parser for PHP What is this? A set of PHP classes, each representing a Markdown flavor, and a command line to

PHP 5.3+ Extensible Dumper
PHP 5.3+ Extensible Dumper

Ladybug: PHP 5.3+ Extensible Dumper Ladybug provides an easy and extensible var_dump / print_r replacement for PHP 5.3+ projects. Any PHP variable, ob

An extensible micro-framework for PHP

What is Flight? Flight is a fast, simple, extensible framework for PHP. Flight enables you to quickly and easily build RESTful web applications. requi

A configurable and extensible PHP web spider

Note on backwards compatibility break: since v0.5.0, Symfony EventDispatcher v3 is no longer supported and PHP Spider requires v4 or v5. If you are st

Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.
Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.

league/commonmark league/commonmark is a highly-extensible PHP Markdown parser created by Colin O'Dell which supports the full CommonMark spec and Git

Laravel SEO - This is a simple and extensible package for improving SEO via meta tags, such as OpenGraph tags.

This is a simple and extensible package for improving SEO via meta tags, such as OpenGraph tags.

A simple and extensible fixture loader for PHP 7.3+, supporting SQLite and MySQL

Flowder Flowder is a (really) simple fixture loader for PHP 7.3+, supporting SQLite and MySQL. Using Flowder in PHP 7.2 or below? Try version 1 instea

BEdita, ready to use back-end API, extensible API-first Content Management

BEdita, a back-end API BEdita 4 is a ready to use back-end API to handle the data of your mobile, IoT, web and desktop applications. It's also an exte

A multilingual, extensible, community oriented CMS developed in PHP
A multilingual, extensible, community oriented CMS developed in PHP

ImpressCMS is a community developed Content Management System. With this tool maintaining the content of a website becomes as easy as writing a word d

A simple, extensible REST API framework for PHP

Note: This framework is not stable yet. Introduction Aphiria is a suite of small, decoupled PHP libraries that make up a REST API framework. It simpli

Framework for building extensible server-side progressive applications for modern PHP.
Framework for building extensible server-side progressive applications for modern PHP.

Chevere 🔔 Subscribe to the newsletter to don't miss any update regarding Chevere. Framework for building extensible server-side progressive applicati

Laravel Boilerplate provides a very flexible and extensible way of building your custom Laravel applications.
Laravel Boilerplate provides a very flexible and extensible way of building your custom Laravel applications.

Laravel Boilerplate Project Laravel Boilerplate provides a very flexible and extensible way of building your custom Laravel applications. Table of Con

A simple but extensible economy engine for PocketMine-MP, using label-oriented APIs.

Capital A simple but very extensible economy plugin for PocketMine-MP. How is Capital different from other economy plugins? Capital introduces a label

Simple, extensible and powerful enumeration implementation for Laravel.

About Laravel Enum Simple, extensible and powerful enumeration implementation for Laravel. Enum key value pairs as class constants Full featured suite

Owner
TheCodingMachine
TheCodingMachine
The dependency injection container for humans

layout home PHP-DI is a dependency injection container meant to be practical, powerful, and framework-agnostic. Read more on the website: php-di.org G

null 2.4k Jan 4, 2023
Small but powerful dependency injection container

Container (Dependency Injection) This package is compliant with PSR-1, PSR-2, PSR-4 and PSR-11. If you notice compliance oversights, please send a pat

The League of Extraordinary Packages 779 Dec 30, 2022
💎 Flexible, compiled and full-featured Dependency Injection Container with perfectly usable autowiring and support for all new PHP 7 features.

Nette Dependency Injection (DI) Introduction Purpose of the Dependecy Injection (DI) is to free classes from the responsibility for obtaining objects

Nette Foundation 781 Dec 15, 2022
PSR-11 compatible Dependency Injection Container for PHP.

bitexpert/disco This package provides a PSR-11 compatible, annotation-based dependency injection container. Have a look at the disco-demos project to

bitExpert AG 137 Sep 29, 2022
🚀 PHP Service Container with fast and cachable dependency injection.

ClanCats Container A PHP Service Container featuring a simple meta-language with fast and compilable dependency injection. Requires PHP >= 7.0 Pros: M

ClanCats 28 Apr 13, 2022
DI Container (PSR-11)

My DI Container It's my own implementation PSR-11 Container Interface. Installation composer require scruwi/container Init $container = new Container(

null 4 Mar 15, 2022
This repository holds all interfaces related to PSR-11 (Container Interface).

Container interface This repository holds all interfaces related to PSR-11 (Container Interface). Note that this is not a Container implementation of

PHP-FIG 9.6k Jan 4, 2023
Twittee is the smallest, and still useful, Dependency Injection Container in PHP

What is Twittee? Twittee is the smallest, and still useful, Dependency Injection Container in PHP; it is also probably one of the first public softwar

null 133 Dec 5, 2022
Easy integration of twitters bootstrap into symfony2

MopaBootstrapBundle MopaBootstrapBundle is a collection of code to integrate twitter's bootstrap (http://twitter.github.com/bootstrap/) as easy as pos

Philipp A. Mohrenweiser 717 Dec 15, 2022
BraincraftedBootstrapBundle integrates Bootstrap into Symfony2 by providing templates, Twig extensions, services and commands.

BraincraftedBootstrapBundle BraincraftedBootstrapBundle helps you integrate Bootstrap in your Symfony2 project. BootstrapBundle also supports the offi

Braincrafted 403 Aug 13, 2022