3d7d378cbc
* 2.3: 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 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/Config/Tests/Definition/ScalarNodeTest.php src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformerTest.php src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php src/Symfony/Component/Locale/Tests/LocaleTest.php src/Symfony/Component/Locale/Tests/Stub/StubLocaleTest.php src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.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 | ||
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%')
->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