Symfony4 迁移:"doctrine.database_create_command" 服务是私有的

Symfony4 migration: The "doctrine.database_create_command" service is private

我开始将我的应用程序迁移到 symfony4,但我的一个第三方包 (tbbcmoneybundle 中有以下弃用通知。我想知道要更改哪些内容才能提出建议PR

目前由于这些错误构建失败(完整报告here

The "doctrine.database_create_command" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead: 25x
    12x in ConfigTest::setUp from Tbbc\MoneyBundle\Tests\Config
    6x in ConsoleTest::setUp from Tbbc\MoneyBundle\Tests\Console
    3x in ConsoleTest::testRunRatioList from Tbbc\MoneyBundle\Tests\Console
    2x in ConsoleTest::testRunRatioFetch from Tbbc\MoneyBundle\Tests\Console
    1x in ConfigTest::testHistoryOfFetchedRatio from Tbbc\MoneyBundle\Tests\Config
    1x in ConsoleTest::testRunSaveRatio from Tbbc\MoneyBundle\Tests\Console

我想这与这段代码有关

    $this->runCommand($this->client,'doctrine:database:create');
    $this->runCommand($this->client,'doctrine:schema:update --force');

但是我不知道如何解决这个问题,google 似乎对这个没有帮助。

这个问题看起来是由于 Symfony 4 中容器意识的丢失(如果这是一个有效的短语),从 Symfony 3.4 开始。本博客talks about restricting container injection in 3.4 and how it will go away in 4.0

看起来好像有人 opened a PR to upgrade to Symfony 4, but that is failing。 (看起来你也在努力帮助它。)

根据 this Travis integration test that is failing,扩展 "ContainerAwareCommand" 的命令是失败的根源。

这是有道理的。 ContainerAwareCommand 尝试注入 Container,它在 Symfony 4 中设置为 private(并且自 3.4 起已弃用),如上面的博客 post 中所述。如果我正确阅读了你的问题,我想你想在 TBBC 的 PR 中修复这个问题,似乎是从那些命令 类 中删除 ContainerAwareCommand 的扩展,并只注入必要的服务。见new Symfony 4 doc on commands (and note that ContainerAware is no longer an option as it was in 2.8-ish.)

简而言之,摆脱 ContainerAwareCommand 的扩展并注入这些命令使用的服务。 (可能需要 do some extra configuration to ensure that the services are public。)