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

时间:2017-12-30 23:38:48

标签: php symfony doctrine-orm symfony3.x symfony4

我开始将我的应用程序迁移到symfony4,但是我的第三方软件包(tbbcmoneybundle)中有以下弃用通知。我想知道要改变什么以便提议公关

目前,由于这些错误(完整报告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');

但是,我没有看到如何解决此问题,谷歌似乎对此无益。

1 个答案:

答案 0 :(得分:1)

问题看起来像是在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以来已弃用),如上面的博客文章中所述。一个修复,我想如果我正确地读出你的问题,你想在PRBC中解决这个问题,似乎是从那些命令类中删除ContainerAwareCommand的扩展,只是注入必要的服务。请参阅new Symfony 4 doc on commands(并注意ContainerAware不再是it was in 2.8-ish的选项。)

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