feaee3615f
* 2.2: (26 commits) [FrameworkBundle] Fixes invalid serialized objects in cache remove dead code in yaml component Fixed typo in UPGRADE-2.2 fixed typo RedisProfilerStorage wrong db-number/index-number selected [DependencyInjection] added a test for the previous merge (refs #7261) Unset loading[$id] in ContainerBuilder on exception Default validation message translation fix. remove() should not use deprecated getParent() so it does not trigger deprecation internally adjust routing tests to not use prefix in addCollection add test for uniqueness of resources added tests for addDefaults, addRequirements, addOptions adjust RouteCollectionTest for the addCollection change and refactor the tests to only skip the part that really needs the config component added tests for remove() that wasnt covered yet and special route name refactor interator test that was still assuming a tree adjust tests to no use addPrefix with options adjusted tests to not use RouteCollection::getPrefix [Routing] trigger deprecation warning for deprecated features that will be removed in 2.3 [Console] fixed StringInput binding [Console] added string input test ... |
||
---|---|---|
.. | ||
Compiler | ||
Dumper | ||
Exception | ||
Extension | ||
Loader | ||
ParameterBag | ||
Tests | ||
.gitignore | ||
Alias.php | ||
CHANGELOG.md | ||
composer.json | ||
Container.php | ||
ContainerAware.php | ||
ContainerAwareInterface.php | ||
ContainerBuilder.php | ||
ContainerInterface.php | ||
Definition.php | ||
DefinitionDecorator.php | ||
IntrospectableContainerInterface.php | ||
LICENSE | ||
Parameter.php | ||
phpunit.xml.dist | ||
README.md | ||
Reference.php | ||
Scope.php | ||
ScopeInterface.php | ||
SimpleXMLElement.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%')
->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 --dev
$ phpunit