Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
[READ-ONLY] Subtree split of the Symfony DependencyInjection Component -- clone into Symfony/Component/ (master at symfony/symfony)

Merge branch '2.7'

* 2.7:
  [RFC][Console] Added console style guide helpers (v2)
  [Validator] Add missing pt_BR translations
  [Translation][Profiler] Added a Translation profiler.
  Add parsing of hexadecimal strings for PHP 7
  [VarDumper] Add filters to casters
  Trim final stop from deprecation message
  [Configuration] improve description for ignoreExtraKeys on ArrayNodeDefinition
  [Validator] Added missing Hungarian translation
  [Validator] Fixed grammar in Hungarian translation
  CS: Unary operators should be placed adjacent to their operands
  CS: Binary operators should be arounded by at least one space
  remove useless tests that fail in php 7
  [Translator] fix test for php 7 compatibility
  [VarDumper] Add VarDumperTestCase and related trait
  Update phpdoc of ProcessBuilder#setPrefix()

latest commit 4d12bccee9
@fabpot fabpot authored
Failed to load latest commit information.
Compiler make it possible to dump inlined services to XML
Dumper Merge branch '2.7'
Exception [DependencyInjection] fixed ? position in some exception messages (re…
Extension [2.3] CS And DocBlock Fixes
LazyProxy made {@inheritdoc} annotations consistent across the board
Loader make it possible to dump inlined services to XML
ParameterBag Merge branch '2.7'
Tests Fix merge
.gitignore Added missing files .gitignore
Alias.php Docblock fixes [DependencyInjection] deprecated synchronized services
Container.php Merge branch '2.5' into 2.6
ContainerAware.php [DependencyInjection] made ContainerAware class abstract.
ContainerAwareInterface.php [FramworkBundle] fix phpdoc of commands
ContainerAwareTrait.php Remove executable bit on PHP file
ContainerBuilder.php Merge branch '2.7'
ContainerInterface.php [2.3] CS And DocBlock Fixes
Definition.php [FrameworkBundle] remove usage of deprecated Definition::setFactoryCl…
DefinitionDecorator.php Merge branch '2.5' into 2.6
ExpressionLanguage.php Fixed minor typo - override
ExpressionLanguageProvider.php [DependencyInjection] added support for custom expression language fu…
IntrospectableContainerInterface.php [2.3] CS And DocBlock Fixes
LICENSE Updated copyright to 2015
Parameter.php [DependencyInjection] tagged the public @api Merge branch '2.3' into 2.6
Reference.php Merge branch '2.3' into 2.5
Scope.php updated license blocks
ScopeInterface.php fixed CS
SimpleXMLElement.php Normalized @deprecated annotations.
TaggedContainerInterface.php fixed CS
Variable.php [2.3] CS And DocBlock Fixes
composer.json Merge branch '2.7'
phpunit.xml.dist [PhpUnitBridge] new bridge for testing with PHPUnit

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.