symfony/symfony — pull request #8850 by fabpot (2013-08-25 08:59:08+00:00)
Title: [WIP] [DependencyInjection] added support for expressions in the service container

| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #7352
| License | MIT
| Doc PR | not yet

This PR introduces a way to inject expression in the definition of a service.

Here is a small usage example:

```php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Expression;

class Foo
{
private $value;

public function __construct($value)
{
$this->value = $value;
}

public function getBarValue()
{
return $this->value;
}
}

class Bar
{
public function getValue()
{
return 'bar';
}
}

$c = new ContainerBuilder();
$c->register('bar', 'Bar');
$c->register('foo', 'Foo')->addArgument(new Expression(new Reference('bar'), 'value'));

echo $c->get('foo')->getBarValue()."\n";
```

The `Expression` constructor takes a service id and a property path (as defined by the Symfony PropertyAccess component). Using the Symfony PropertyAccess component gives you a lot of flexibility in the way you get data from your objects.

This PR just implements the basics as a proof of concept for now.

TODO

- [ ] update documentation
- [ ] update all loaders and dumpers
- [ ] add tests