symfony/symfony — pull request #12115 by unkind (2014-10-03 15:00:25+00:00)
Title: [DependencyInjection] Added closure service factories

| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a

This PR adds closure service factories for the `DependencyInjection` component. There are 2 kinds of closures:
```php
use Symfony\Component\DependencyInjection\ContainerInterface;

// Closure with services/parameters as arguments
$container
->register('bar1', 'Bar')
->setFactory(function (Foo $foo, $bar) {
return new Bar($foo->getQux(), $bar);
})
->addArgument(new Reference('foo'))
->addArgument('%bar%')
;

// Pimple-like closure with container as an argument
$container
->register('bar2', 'Bar')
->setFactory(function (ContainerInterface $container) {
return new Bar($container->get('foo')->getQux(), $container->getParameter('bar'));
})
;
```
It would be useful for something like `ArrayFileLoader` described in #11953.