This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection
Fabien Potencier 47c686db88 Merge branch '2.4' into 2.5
* 2.4:
  updated VERSION for 2.4.7
  updated CHANGELOG for 2.4.7
  bumped Symfony version to 2.3.18
  updated VERSION for 2.3.17
  update CONTRIBUTORS for 2.3.17
  updated CHANGELOG for 2.3.17
  added XSD to PHPUnit configuration
  add missing docblock for ProcessBuilder::addEnvironmentVariables()
  bug #11319 [HttpKernel] Ensure the storage exists before purging it in ProfilerTest
  [Translation] Added unescaping of ids in PoFileLoader
  updated italian translation for validation messages
  [DomCrawler] Fix docblocks and formatting.
  [DomCrawler] Remove the query string and the anchor of the uri of a link
  Simplified the Travis test command
  Remove Expression Language services when the component is unavailable
  [Console] Make sure formatter is the same

Conflicts:
	src/Symfony/Component/HttpKernel/Kernel.php
2014-07-08 14:21:33 +02:00
..
Compiler Merge branch '2.4' 2014-04-18 22:40:13 +02:00
Dumper GraphizDumper now displays unresolved parameters 2014-05-09 16:22:29 +02:00
Exception [DependencyInjection] fixed ? position in some exception messages (refs #7861) 2013-05-01 06:24:56 +02:00
Extension [DependencyInjection] Fix parameter description in ConfigurationExtensionInterface 2014-05-02 22:42:57 +00:00
LazyProxy made {@inheritdoc} annotations consistent across the board 2014-04-16 09:04:20 +02:00
Loader Merge branch '2.4' 2014-04-16 12:36:21 +02:00
ParameterBag Merge branch '2.3' into 2.4 2014-04-16 12:34:31 +02:00
Tests Merge branch '2.4' 2014-05-12 11:28:39 +02:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
Alias.php fixed types in phpdocs 2014-04-16 12:30:19 +02:00
CHANGELOG.md [DependencyInjection] Deprecate SimpleXMLElement 2014-04-02 17:32:21 +02:00
composer.json updated version to 2.5 2013-11-24 21:17:07 +01:00
Container.php Merge branch '2.3' into 2.4 2014-04-18 22:37:09 +02:00
ContainerAware.php [DependencyInjection] made ContainerAware class abstract. 2012-05-30 09:01:58 +02:00
ContainerAwareInterface.php [FramworkBundle] fix phpdoc of commands 2013-03-07 14:36:36 +01:00
ContainerAwareTrait.php Remove executable bit on PHP file 2013-11-19 14:48:58 +01:00
ContainerBuilder.php Remove undefined variable $e 2014-06-03 03:40:41 +02:00
ContainerInterface.php fixed types in phpdocs 2014-04-16 12:30:19 +02:00
Definition.php Merge branch '2.4' 2014-04-16 12:36:21 +02:00
DefinitionDecorator.php Merge branch '2.3' into 2.4 2014-04-16 10:02:57 +02:00
ExpressionLanguage.php [ExpressionLanguage] renamed addFunction() to register() 2013-09-21 20:20:49 +02:00
IntrospectableContainerInterface.php fixed types in phpdocs 2014-04-16 12:30:19 +02:00
LICENSE update year on licenses 2014-01-07 08:19:25 -05:00
Parameter.php [DependencyInjection] tagged the public @api 2011-07-20 10:50:27 +02:00
phpunit.xml.dist added XSD to PHPUnit configuration 2014-07-07 11:57:21 +02:00
README.md updated the composer install command to reflect changes in Composer 2013-09-18 09:27:26 +02:00
Reference.php Merge branch '2.3' into 2.4 2014-04-16 12:34:31 +02:00
Scope.php updated license blocks 2012-03-31 18:00:32 -03:00
ScopeInterface.php fixed CS 2012-07-09 14:54:20 +02:00
SimpleXMLElement.php Merge branch '2.4' 2014-04-16 10:08:40 +02:00
TaggedContainerInterface.php fixed CS 2012-07-09 14:54:20 +02:00
Variable.php fixed CS 2011-06-08 12:16:48 +02:00

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();
$sc
    ->register('foo', '%foo.class%')
    ->addArgument(new Reference('bar'))
;
$sc->setParameter('foo.class', 'Foo');

$sc->get('foo');

Method Calls (Setter Injection):

$sc = new ContainerBuilder();

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

$sc->get('bar');

Factory Class:

If your service is retrieved by calling a static method:

$sc = new ContainerBuilder();

$sc
    ->register('bar', '%bar.class%')
    ->setFactoryClass('%bar.class%')
    ->setFactoryMethod('getInstance')
    ->addArgument('Aarrg!!!')
;
$sc->setParameter('bar.class', 'Bar');

$sc->get('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();

$sc
    ->register('bar', '%bar.class%')
    ->setFile('/path/to/file')
    ->addArgument('Aarrg!!!')
;
$sc->setParameter('bar.class', 'Bar');

$sc->get('bar');

Resources

You can run the unit tests with the following command:

$ cd path/to/Symfony/Component/DependencyInjection/
$ composer.phar install
$ phpunit