Skip to content


Subversion checkout URL

You can clone with
Download ZIP
[READ-ONLY] Subtree split of the Symfony DependencyInjection Component -- clone into Symfony/Component/ (master at symfony/symfony)
Latest commit 48c4a90 @fabpot fabpot Merge branch '2.8'
* 2.8:
  removed usage of the deprecated StringUtils::equals() method
  Fix: Resolve tempdir symlink, not working on OSX
  fixed tests
  migrate session after remember me authentication
  prevent timing attacks in digest auth listener
  mitigate CSRF timing attack vulnerability
  fix potential timing attack issue
  [WebProfilerBundle] Added a top left border radius to the minified to…
  [Routing] Changing RouteCollectionBuilder::import() behavior to add to the builder
  [HttpKernel] Don't reset on shutdown but in FrameworkBundle/Test/KernelTestCase
  [Process] PhpExecutableFinder: add regression test
Failed to load latest commit information.
Compiler Merge branch '2.8'
Dumper Merge branch '2.8'
Exception [DI] Remove deprecated scope concept
Extension remove api tags from code
LazyProxy made {@inheritdoc} annotations consistent across the board
Loader [3.0] Various deprecations cleanups
ParameterBag Merge branch '2.8'
Tests Merge branch '2.8'
.gitignore Added missing files .gitignore
Alias.php remove api tags from code Merge branch '2.8'
Container.php Merge branch '2.8'
ContainerAwareInterface.php [DI] Clean a phpdoc
ContainerAwareTrait.php Merge branch '2.3' into 2.7
ContainerBuilder.php Merge branch '2.8'
ContainerInterface.php Merge branch '2.8'
Definition.php Merge branch '2.8'
DefinitionDecorator.php Merge branch '2.8'
ExpressionLanguage.php Fixed minor typo - override
ExpressionLanguageProvider.php [DependencyInjection] added support for custom expression language fu…
LICENSE Updated copyright to 2015
Parameter.php remove api tags from code Merge branch '2.3' into 2.6
Reference.php Merge branch '2.8'
ResettableContainerInterface.php Implement resettable containers
TaggedContainerInterface.php remove api tags from code
Variable.php [2.3] CS And DocBlock Fixes
composer.json Merge branch '2.8'
phpunit.xml.dist Add missing exclusions from phpunit.xml.dist

DependencyInjection Component

DependencyInjection manages your services via a robust and flexible Dependency Injection Container.

Here is a simple example that shows how to register services and parameters:

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

$sc = new ContainerBuilder();
    ->register('foo', '%foo.class%')
    ->addArgument(new Reference('bar'))
$sc->setParameter('foo.class', 'Foo');


Method Calls (Setter Injection):

$sc = new ContainerBuilder();

    ->register('bar', '%bar.class%')
    ->addMethodCall('setFoo', array(new Reference('foo')))
$sc->setParameter('bar.class', 'Bar');


Factory Class:

If your service is retrieved by calling a static method:

$sc = new ContainerBuilder();

    ->register('bar', '%bar.class%')
    ->setFactory(array('%bar.class%', 'getInstance'))
$sc->setParameter('bar.class', 'Bar');


File Include:

For some services, especially those that are difficult or impossible to autoload, you may need the container to include a file before instantiating your class.

$sc = new ContainerBuilder();

    ->register('bar', '%bar.class%')
$sc->setParameter('bar.class', 'Bar');



You can run the unit tests with the following command:

$ cd path/to/Symfony/Component/DependencyInjection/
$ composer install
$ phpunit
Something went wrong with that request. Please try again.