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 3bdf52a16a fixed CS
2012-05-18 19:42:42 +02:00
..
Compiler fixed CS 2012-05-18 19:42:42 +02:00
Dumper fixed CS 2012-05-18 19:42:42 +02:00
Exception updated license blocks 2012-03-31 18:00:32 -03:00
Extension fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
Loader fixed CS 2012-05-18 19:42:42 +02:00
ParameterBag fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
Tests merged 2.0 2012-05-11 18:14:47 +02:00
.gitignore [Components] Tests/Autoloading fixes 2012-05-01 17:51:41 +02:00
Alias.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
CHANGELOG.md [DependencyInjection] added CHANGELOG 2012-04-26 22:08:43 +02:00
composer.json updated minimum PHP version to 5.3.3 2012-05-07 10:29:11 +02:00
Container.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
ContainerAware.php [DependencyInjection] tagged the public @api 2011-07-20 10:50:27 +02:00
ContainerAwareInterface.php [DependencyInjection] tagged the public @api 2011-07-20 10:50:27 +02:00
ContainerBuilder.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
ContainerInterface.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
Definition.php fixed CS 2012-05-18 19:42:42 +02:00
DefinitionDecorator.php fixed CS 2012-05-18 19:42:42 +02:00
IntrospectableContainerInterface.php fixed CS 2012-05-01 15:23:48 +02:00
LICENSE Updated LICENSE files copyright 2012-02-22 10:10:37 +01:00
Parameter.php [DependencyInjection] tagged the public @api 2011-07-20 10:50:27 +02:00
phpunit.xml.dist [Components] Tests/Autoloading fixes 2012-05-01 17:51:41 +02:00
README.md [Components] Tests/Autoloading fixes 2012-05-01 17:51:41 +02:00
Reference.php [DependencyInjection] Made the reference case insensitive 2011-12-08 16:30:50 +01:00
Scope.php updated license blocks 2012-03-31 18:00:32 -03:00
ScopeInterface.php updated license blocks 2012-03-31 18:00:32 -03:00
SimpleXMLElement.php [DoctrineBridge] fixed some CS 2011-12-13 10:22:12 +01:00
TaggedContainerInterface.php [DependencyInjection] tagged the public @api 2011-07-20 10:50:27 +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:

phpunit

If you also want to run the unit tests that depend on other Symfony Components, install dev dependencies before running PHPUnit:

php composer.phar install --dev