PHP-DI Symfony Bridge 如何工作以及如何正确设置它?

How does PHP-DI Symfony Bridge work and how to set up it correctly?

通过让 PHP-DI 6 和 Symfony 4 组合工作,我有 some problems。所以我想更深入地了解它是如何工作的/应该如何工作并检查我是否真的正确配置了它。

Symfony 默认使用它自己的 DI 容器,symfony/dependency-injection。在 App\Kernel 中有一个 "hook" 方法 configureContainer(...)。在这种方法中,可以配置 DIC。 DIC 配置的另一个地方是 services.yaml.

现在我安装 php-di/php-diphp-di/symfony-bridge 并在 App\Kernel#buildPHPDIContainer(...) 中进行设置,如 PHP-DI docu 中所述:

/*
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();
    }
}

理论部分:

之后会发生什么/应该发生什么? Symfony DIC 是否变为非活动状态?如果不是,是否意味着该应用程序同时使用了两个 DIC?禁用 Symfony 的 DIC 有意义吗?

总的来说:PHP-DI Symfony Bridge 的想法/方法是什么——替换 框架的 DIC 或 集成自己进去了吗?

实践部分:

我在上面描述了让 PHP-DI 与 Symfony 一起工作的设置步骤。还有别的事情要做吗?例如。 AppKernel\configureContainer(...) 应该保持原样还是应该成为 PHP-DI 的 AppKernel\buildPHPDIContainer(...) 的代理?应该删除 services.yaml 吗?

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?

SymfonyContainerBridge 替换了 Symfony 容器。这个“桥”是 PHP-DI 和 Symfony DI 的代理:如果在 Symfony 的 DI 容器中找到一个条目,它 returns 它,否则它在 PHP-DI.

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?

不是真的,因为 Symfony 中的很多东西只有在 Symfony 的 DI 容器的配置下才能工作。

Is there something else to do?

如果您已按照文档中描述的步骤进行操作,则无需执行其他操作。

关于你的另一个问题I've posted an answer yesterday