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
2013-09-21 20:20:49 +02:00
..
Compiler Allow null values as tag attributes 2013-09-16 10:01:04 +02:00
Dumper merged branch fabpot/expression-engine (PR #8913) 2013-09-19 13:00:34 +02:00
Exception [DependencyInjection] fixed ? position in some exception messages (refs #7861) 2013-05-01 06:24:56 +02:00
Extension Merge branch '2.2' into 2.3 2013-09-19 11:45:20 +02:00
LazyProxy fixed CS 2013-07-01 14:24:43 +02:00
Loader merged branch fabpot/expression-engine (PR #8913) 2013-09-19 13:00:34 +02:00
ParameterBag [DependencyInjection] Added some check before guessing similar parameters 2013-04-30 20:00:41 +02:00
Tests merged branch fabpot/expression-engine (PR #8913) 2013-09-19 13:00:34 +02:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
Alias.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
CHANGELOG.md [DependencyInjection] added support for expressions in the service container 2013-09-19 12:59:10 +02:00
composer.json [DependencyInjection] added support for expressions in the service container 2013-09-19 12:59:10 +02:00
Container.php Use isset() instead of array_key_exists() in DIC 2013-09-03 12:21:15 +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 Add container aware trait 2013-08-28 20:20:21 +02:00
ContainerBuilder.php mades things more consistent for the end user 2013-09-19 12:59:11 +02:00
ContainerInterface.php merged 2.0 2012-09-17 22:41:57 +02:00
Definition.php ProxyManager Bridge 2013-05-06 08:38:39 +02:00
DefinitionDecorator.php [DependencyInjection] fixed #8570 2013-07-25 13:55:15 +08:00
ExpressionLanguage.php [ExpressionLanguage] renamed addFunction() to register() 2013-09-21 20:20:49 +02:00
IntrospectableContainerInterface.php fixed CS 2012-07-09 14:54:20 +02:00
LICENSE updated license year 2013-01-04 17:59:43 +01:00
Parameter.php [DependencyInjection] tagged the public @api 2011-07-20 10:50:27 +02:00
phpunit.xml.dist made usage of Composer autoloader for subtree-split unit tests 2012-11-09 14:10:06 +01:00
README.md updated the composer install command to reflect changes in Composer 2013-09-18 09:27:26 +02:00
Reference.php optimize some unneeded casts (esp. when casting something to string for array access) 2013-08-09 08:59:22 +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 [DependencyInjection] added support for expressions in the service container 2013-09-19 12:59:10 +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