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 48b25f5251 Merge branch '2.8'
* 2.8:
  Fix the FrameworkBundle dependencies
  [DoctrineBridge] Fix required guess of boolean fields
  [DI] don't use array_map to resolve services
  Remove dead code in the PropertyPath constructor
  [EventDispatcher] fix docblock
  [Process] Inherit env vars by default in PhpProcess
  Changed one console output style to avoid visual issues
  [VarDumper] Fix return type and anonymous classes dumping
  [FrameworkBundle] PropertyInfo support
  [HttpFoundation] Fixes /0 subnet handling in IpUtils
  [Form] Simplify DateTimeToStringTransformer Avoid unneeded catch and re-throw of the same exception.
  [Minor] [Serializer] Removed second license header
  [TwigBundle] added a Twig templates warmer when templating is disabled
  [HttpKernel] Remove a duplicate test for the EsiFragmentRenderer
  [Templating] deprecate low-level RouterHelper::generate method as it's cumbersome to use constants in templates
  [Templating] introduce path and url methods in php templates to be in line with twig templates
  [Routing] deprecate the old url generator reference type values
  [Routing] use constant in a test that is new in 2.7
  [FrameworkBundle] Add a new ClassCache cache warmer
  [Validator] Add expressionLanguage to ExpressionValidator constructor

Conflicts:
	src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml
	src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
	src/Symfony/Bundle/FrameworkBundle/composer.json
	src/Symfony/Component/BrowserKit/composer.json
	src/Symfony/Component/ClassLoader/ClassCollectionLoader.php
	src/Symfony/Component/EventDispatcher/EventDispatcher.php
2015-10-23 17:08:51 +02:00
..
Compiler Merge branch '2.8' 2015-10-16 13:55:41 +02:00
Dumper Merge branch '2.8' 2015-09-29 16:08:28 +02:00
Exception [DI] Remove deprecated scope concept 2015-09-04 22:04:06 +02:00
Extension remove api tags from code 2015-09-28 19:11:22 +02:00
LazyProxy made {@inheritdoc} annotations consistent across the board 2014-04-16 09:04:20 +02:00
Loader [3.0] Various deprecations cleanups 2015-10-06 09:31:12 +02:00
ParameterBag Merge branch '2.8' 2015-09-29 16:08:28 +02:00
Tests Merge branch '2.8' 2015-10-10 12:22:50 +02:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
Alias.php remove api tags from code 2015-09-28 19:11:22 +02:00
CHANGELOG.md Merge branch '2.8' 2015-09-06 10:47:32 +02:00
composer.json Merge branch '2.8' 2015-10-10 12:22:50 +02:00
Container.php Merge branch '2.8' 2015-09-29 16:08:28 +02:00
ContainerAware.php remove api tags from code 2015-09-28 19:11:22 +02:00
ContainerAwareInterface.php remove api tags from code 2015-09-28 19:11:22 +02:00
ContainerAwareTrait.php Remove executable bit on PHP file 2013-11-19 14:48:58 +01:00
ContainerBuilder.php Merge branch '2.8' 2015-10-23 17:08:51 +02:00
ContainerInterface.php Merge branch '2.8' 2015-09-29 16:08:28 +02:00
Definition.php Merge branch '2.8' 2015-10-05 17:24:55 +02:00
DefinitionDecorator.php Merge branch '2.8' 2015-09-29 16:08:28 +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
LICENSE Updated copyright to 2015 2015-01-01 13:56:52 +01:00
Parameter.php remove api tags from code 2015-09-28 19:11:22 +02:00
phpunit.xml.dist Merge branch '2.3' into 2.7 2015-10-11 11:39:48 +02:00
README.md Merge branch '2.3' into 2.6 2015-02-11 08:12:14 +01:00
Reference.php Merge branch '2.8' 2015-09-29 16:08:28 +02:00
ResettableContainerInterface.php Implement resettable containers 2015-07-22 10:09:28 +02:00
TaggedContainerInterface.php remove api tags from code 2015-09-28 19:11:22 +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