Skip to content
[READ-ONLY] Subtree split of the Symfony DependencyInjection Component
Latest commit 18bde48 @nicolas-grekas nicolas-grekas Merge branch '3.0'
* 3.0:
  [VarDumper] Fix tests on PHP 7
  [DomCrawler] Clarify the value returned by getPhpFiles()
  [DependencyInjection] Fix #16461 Let Container::set() replace existing aliases
  avoid (string) catchable fatal error for instances of __PHP_Incomplete_Class
  remove unnecessary retrieval and setting of data
  avoid (string) catchable fatal error for __PHP_Incomplete_Class instances
  sendContent return as parent.
  [DomCrawler] Remove the overridden getHash() method to prevent problems when cloning the crawler
  [FrameworkBundle] Fix a typo
  Added more exceptions to singularify method
  Add width attribute on SVG
  [FrameworkBundle] Support autowiring for TranslationInterface
  [Validator] remove obsolete context and PropertyAccess code
  [WebProfiler] Fixed styles for search block and menu profiler for IE Edge
Failed to load latest commit information.
Compiler Merge branch '3.0'
Dumper minor #17465 Remove unused imports (Koc)
Exception [DI] Remove deprecated scope concept
Extension [2.3] Static Code Analysis for Components
LazyProxy made {@inheritdoc} annotations consistent across the board
Loader Merge branch '3.0'
ParameterBag Merge branch '2.8'
Tests Merge branch '3.0'
.gitignore Added missing files .gitignore
Alias.php remove api tags from code Merge branch '2.8'
Container.php Merge branch '2.8' into 3.0
ContainerAwareInterface.php [DI] Clean a phpdoc
ContainerAwareTrait.php Merge branch '2.3' into 2.7
ContainerBuilder.php Merge branch '2.8' into 3.0
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 Update copyright year
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 updated version to 3.1
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.