48b25f5251
* 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 |
||
---|---|---|
.. | ||
Compiler | ||
Dumper | ||
Exception | ||
Extension | ||
LazyProxy | ||
Loader | ||
ParameterBag | ||
Tests | ||
.gitignore | ||
Alias.php | ||
CHANGELOG.md | ||
composer.json | ||
Container.php | ||
ContainerAware.php | ||
ContainerAwareInterface.php | ||
ContainerAwareTrait.php | ||
ContainerBuilder.php | ||
ContainerInterface.php | ||
Definition.php | ||
DefinitionDecorator.php | ||
ExpressionLanguage.php | ||
ExpressionLanguageProvider.php | ||
LICENSE | ||
Parameter.php | ||
phpunit.xml.dist | ||
README.md | ||
Reference.php | ||
ResettableContainerInterface.php | ||
TaggedContainerInterface.php | ||
Variable.php |
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