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
Nicolas Grekas 48aa3e1453 Merge branch '2.7' into 2.8
* 2.7:
  [Locale] Add missing @group legacy annotations
  Fix security-acl deps
  Fix doctrine mapping validation type error
  Remove skipping of tests based on ICU data version whenever possible
  Fix the handling of null as locale in the stub intl classes
  do not dump leading backslashes in class names
  fix issue #15377
  Skip ::class constant
  [Config] type specific check for emptiness

Conflicts:
	src/Symfony/Bridge/Twig/composer.json
	src/Symfony/Bundle/SecurityBundle/composer.json
	src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php
	src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php
	src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php
2015-08-01 11:43:59 +02:00
..
Compiler Merge remote-tracking branch 'origin/2.7' into 2.8 2015-07-01 14:16:54 +00:00
Dumper Merge branch '2.7' into 2.8 2015-08-01 11:43:59 +02:00
Exception [DependencyInjection] fixed ? position in some exception messages (refs #7861) 2013-05-01 06:24:56 +02:00
Extension [2.3] CS And DocBlock Fixes 2014-12-22 16:58:09 +01:00
LazyProxy made {@inheritdoc} annotations consistent across the board 2014-04-16 09:04:20 +02:00
Loader Merge branch '2.7' into 2.8 2015-07-22 13:24:41 +02:00
ParameterBag Merge branch '2.3' into 2.7 2015-07-28 16:07:07 +02:00
Tests Merge branch '2.7' into 2.8 2015-08-01 11:43:59 +02: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 Implement resettable containers 2015-07-22 10:09:28 +02:00
composer.json Merge branch '2.7' into 2.8 2015-05-12 17:16:46 +02:00
Container.php Implement resettable containers 2015-07-22 10:09:28 +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 Add "shared" flag and deprecate scopes concept 2015-06-24 12:32:32 -03:00
ContainerInterface.php Add "shared" flag and deprecate scopes concept 2015-06-24 12:32:32 -03:00
Definition.php Make service not shared when prototype scope is set 2015-06-24 22:39:48 +02:00
DefinitionDecorator.php [DependencyInjection] Fixed decoration of service for service with parent 2015-05-18 11:41:40 +02:00
ExpressionLanguage.php Fixed minor typo - override 2015-01-03 21:58:03 +01:00
ExpressionLanguageProvider.php [DependencyInjection] added support for custom expression language functions 2014-09-25 19:08:38 +02:00
IntrospectableContainerInterface.php [2.3] CS And DocBlock Fixes 2014-12-22 16:58:09 +01:00
LICENSE Updated copyright to 2015 2015-01-01 13:56:52 +01:00
Parameter.php [DependencyInjection] tagged the public @api 2011-07-20 10:50:27 +02:00
phpunit.xml.dist [2.3] require-dev PHPUnit bridge 2015-02-24 11:24:26 +01:00
README.md Merge branch '2.3' into 2.6 2015-02-11 08:12:14 +01:00
Reference.php Add "shared" flag and deprecate scopes concept 2015-06-24 12:32:32 -03:00
ResettableContainerInterface.php Implement resettable containers 2015-07-22 10:09:28 +02:00
Scope.php Add "shared" flag and deprecate scopes concept 2015-06-24 12:32:32 -03:00
ScopeInterface.php Add "shared" flag and deprecate scopes concept 2015-06-24 12:32:32 -03:00
SimpleXMLElement.php Silence invasive deprecation warnings, opt-in for warnings 2015-06-08 10:37:21 +01:00
TaggedContainerInterface.php fixed CS 2012-07-09 14:54:20 +02:00
Variable.php [2.3] CS And DocBlock Fixes 2014-12-22 16:58:09 +01: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%')
    ->setFactory(array('%bar.class%', '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 install
$ phpunit