mnapoli/PHP-DI-Symfony2 — pull request #4 by mnapoli (2014-09-04 15:57:06+00:00)
Title: Symfony container entries can reference PHP-DI's entries

Fucking finally!

Symfony entires can reference PHP-DI entires. For example:

```yaml
services:
myservice:
class: My\Service
arguments: [ "@My\Other\Service" ]
```

Here `My\Other\Service` is a service that PHP-DI will provide (not Symfony).

That's the solution if you need to use **tags** (e.g. voters, …) for a specific service -> you define it in Symfony (YAML) and you can still inject PHP-DI services into it.

And the whole thing is even easier than before. Currently, what you have to do:

```php
class AppKernel extends Kernel
{
// ...

protected function getContainerBaseClass()
{
return 'DI\Bridge\Symfony\SymfonyContainerBridge';
}

protected function initializeContainer()
{
parent::initializeContainer();

$builder = new \DI\ContainerBuilder();
$builder->wrapContainer($this->getContainer());

// Configure your container here
$builder->addDefinitions(__DIR__ . '/config/config.php');

$this->getContainer()->setFallbackContainer($builder->build());
}
}
```

Now with this branch, you only do this:

```php
class AppKernel extends \DI\Bridge\Symfony\Kernel
{
// ...

protected function buildPHPDIContainer(ContainerBuilder $builder)
{
// Configure your container here
$builder->addDefinitions(__DIR__ . '/config/config.php');

return $builder->build();
}
}
```

---

### Warnings

- I had to remove the `CheckExceptionOnInvalidReferenceBehaviorPass` compiler pass.

It checked for unknown references, and since it doesn't know about PHP-DI's entries, they are "unknown references" to it, so it throws exceptions.

I tried to replace it with a custom compiler pass (that would look into PHP-DI too), but PHP-DI is not built yet when Symfony's container is being compiled, so it doesn't seem really possible.

So is that really bad to have removed that compiler pass? Is that worth it? To be discussed.

- The user now has to extend our custom `Kernel` class instead of Symfony's one. I don't see that as a problem, is it?

- This branch breaks BC -> needs a major version bump

- The docs need to be updated

Feedback more than welcome, ping @tentacode