I have some problems by getting the PHP-DI 6 & Symfony 4 combination working. So I'd like to get a deeper understanding, how this works / should work and check, whether I actually configured it correctly.
Symfony uses by default its own DI container, symfony/dependency-injection
. In the App\Kernel
there is a "hook" method configureContainer(...)
. In this method the DIC can be configured. Another place for the DIC configuration is the services.yaml
.
Now I install the php-di/php-di
and the php-di/symfony-bridge
and set it up in the App\Kernel#buildPHPDIContainer(...)
as in the PHP-DI docu explained:
/*
Cannot use ContainerBuilder as in the PHP-DI docu,
since its already in use by the AppKernel\configureContainer(...).
*/
use DI\ContainerBuilder as PhpDiContainerBuilder;
class AppKernel extends \DI\Bridge\Symfony\Kernel
{
// ...
protected function buildPHPDIContainer(PhpDiContainerBuilder $builder)
{
$builder->addDefinitions('/path/to/file/returning/definitions/array.php');
return $builder->build();
}
}
Theoretical part:
What happens / should happen after it? Does the Symfony DIC become inactive? If not, does it mean, that the application uses two DICs in the same time? Make it sense to disable the Symfony's DIC?
In general: What is the idea / approach of the PHP-DI Symfony Bridge -- to replace the framework's DIC or to integrate itself into it?
Practical part:
I described above the setup steps I to get PHP-DI working with Symfony. Is there something else to do? E.g. should the AppKernel\configureContainer(...)
stay as it is or should it become a proxy to the PHP-DI's AppKernel\buildPHPDIContainer(...)
? Should the services.yaml
be removed?
What happens / should happen after it?
What is the idea / approach of the PHP-DI Symfony Bridge -- to replace the framework's DIC or to integrate itself into it?
The SymfonyContainerBridge
replaces the Symfony container. This "bridge" is a proxy to both PHP-DI and Symfony DI: if an entry is found in Symfony's DI container, it returns it, else it looks inside PHP-DI.
Does the Symfony DIC become inactive?
No.
If not, does it mean, that the application uses two DICs in the same time?
Yes.
Make it sense to disable the Symfony's DIC?
Not really because a lot of things in Symfony only work thanks to Symfony's DI container's config.
Is there something else to do?
If you've followed the steps described in the documentation there shouldn't be something else to do.
As for your other question I've posted an answer yesterday.