Commonly used patterns for Symfony2 DI provided out of the box.

0.0.1 2013-09-12 18:44 UTC

This package is not auto-updated.

Last update: 2019-03-08 14:40:41 UTC


ChillDevDependencyInjectionExtra is a library which offers implementation of some commonly used patterns used in Symfony2 DI.

Build Status Scrutinizer Quality Score Coverage Status Dependency Status SensioLabsInsight


This library is provided as Composer package. To install it simply add following dependency definition to your composer.json file:

"chilldev/dependency-injection-extra": "dev-master"

Replace dev-master with different constraint if you want to use specific version.

Note: This library requires PHP 5.4.

Note: This is not a bundle; you don't need to adapt your kernel or any other part of project to use it's goods - just use it directly in your code.


You can use ChillDev\DependencyInjection\Compiler\TagGrabbingPass to automate grabbing all tagged services into container. Consider following DI services:

        class: "YourAdaptersRepository"
        class: "YourFirstAdapter"
            - { name: "your.adapter.tag", adapter: "first" }
        class: "YourSecondAdapter"
            - { name: "your.adapter.tag", adapter: "second" }
        class: "YourThirdAdapter"
            - { name: "your.adapter.tag", adapter: "third" }

Let's say your repository class looks as follows:

class YourAdaptersRepository extends ArrayObject
    public function registerAdapter($key, $adapter)
        $this[$key] = $adapter;

It is a very common setup - now you want to add all services tagged with your.adapter.tag to repository service. Instead of writing your own custom DI compiler pass, you can use ready implementation that will do exactly what you want. It's as easy as:

use ChillDev\DependencyInjection\Compiler\TagGrabbingPass;

use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class YourBundle extends Bundle
    public function build(ContainerBuilder $container)

            new TagGrabbingPass(
                // this is tag name for which you want to look
                // this is ID of container service
                // this is name of method for registering new adapters
                // this is tag attribute name to be used as key identifier

For more advanced aspects see advanced usage documentation or even internals description.



Do you want to help improving this project? Simply fork it and post a pull request. You can do everything on your own, you don't need to ask if you can, just do all the awesome things you want!

This project is published under MIT license.


ChillDevDependencyInjectionExtra is brought to you by Chillout Development.

List of contributors: