47c686db88
* 2.4: updated VERSION for 2.4.7 updated CHANGELOG for 2.4.7 bumped Symfony version to 2.3.18 updated VERSION for 2.3.17 update CONTRIBUTORS for 2.3.17 updated CHANGELOG for 2.3.17 added XSD to PHPUnit configuration add missing docblock for ProcessBuilder::addEnvironmentVariables() bug #11319 [HttpKernel] Ensure the storage exists before purging it in ProfilerTest [Translation] Added unescaping of ids in PoFileLoader updated italian translation for validation messages [DomCrawler] Fix docblocks and formatting. [DomCrawler] Remove the query string and the anchor of the uri of a link Simplified the Travis test command Remove Expression Language services when the component is unavailable [Console] Make sure formatter is the same Conflicts: src/Symfony/Component/HttpKernel/Kernel.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 | ||
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
$ phpunit