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
2014-12-18 20:00:19 +01:00
..
Compiler CS fixes 2014-12-03 20:10:26 +00:00
Dumper Revert "[DependencyInjection] backport perf optim" 2014-12-11 19:19:56 +01:00
Exception [DependencyInjection] fixed ? position in some exception messages (refs #7861) 2013-05-01 06:24:56 +02:00
Extension Docblock fixes 2014-11-30 13:33:44 +00:00
LazyProxy made {@inheritdoc} annotations consistent across the board 2014-04-16 09:04:20 +02:00
Loader [DependencyInjection] use inheritdoc for loaders 2014-10-13 21:10:53 +02:00
ParameterBag Docblock fixes 2014-11-30 13:33:44 +00:00
Tests Revert "[DependencyInjection] backport perf optim" 2014-12-11 19:19:56 +01:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
Alias.php Docblock fixes 2014-11-30 13:33:44 +00:00
CHANGELOG.md [DIC] Better handling of enableable configurations 2013-01-28 18:21:49 +01:00
composer.json Test components using their lowest possible deps 2014-12-15 11:45:17 +01:00
Container.php Docblock fixes 2014-11-30 13:33:44 +00: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
ContainerBuilder.php Docblock fixes 2014-11-30 13:33:44 +00:00
ContainerInterface.php Docblock fixes 2014-11-30 13:33:44 +00:00
Definition.php Docblock fixes 2014-11-30 13:33:44 +00:00
DefinitionDecorator.php Docblock fixes 2014-11-30 13:33:44 +00:00
IntrospectableContainerInterface.php Docblock fixes 2014-11-30 13:33:44 +00: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 [Tests] Silenced all deprecations in tests for 2.3 2014-12-18 20:00:19 +01:00
README.md [Doc] Use Markdown syntax highlighting 2014-10-01 07:38:33 +02:00
Reference.php Docblock fixes 2014-11-30 13:33:44 +00: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 Docblock fixes 2014-11-30 13:33:44 +00: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