试图调用名为" getDefaultName"的未定义方法。

时间:2018-04-20 12:46:57

标签: symfony

我想将symfony从3.3升级到3.4但是当我执行Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op. Please check the code for the MyComponent component. 时,我发现了这个错误:

composer update

在浏览器中,有2条消息:

[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\UndefinedMethodException: Attempted to call an undefined method named "getDefaultName" of class "Doctrine\Bundle\DoctrineCacheBundle\Command\ContainsCommand". in /srv/http/ocim.formations/vendor/symfony/symfony/src/Symfony/Component/Console/DependencyInjectionAddConsoleCommandPass.php:61
Stack trace:
#0 /srv/http/ocim.formations/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php(141): Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass->process(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#1 /srv/http/ocim.formations/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php(759): Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#2 /srv/http/ocim.formations/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(643): Symfony\Component\DependencyInjection\ContainerBuilder->compile in /srv/http/ocim.formations/vendor/symfony/symfony/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php on line 61

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

如上所述here,它可能是由过时的Composer版本引起的,该版本使用较旧的Symfony控制台组件。因此,当Composer以前加载此类的旧版本时,当您的Symfony实例稍后在cache:clear命令中尝试访问此类时,它不会再次自动加载。

解决方案可能是使用composer self-update更新您的Composer。

答案 1 :(得分:0)

我今天遇到了一个类似的问题:我们在项目中使用symfony/console 3.4+,该项目试图通过getDefaultName加载命令名。但是,作曲家内部使用的older version of symfony/console(因为它是added in v3.4.0,因为该方法不存在)。

在这种情况下,composer self-update将无济于事,但是您可以确保将command添加到服务定义中,如下所示:

services:
  myvendorname.mypackagename.foo.command:
    class: MyVendorName\MyPackageName\Command\FooCommand
    tags:
    - { name: 'console.command', command: 'foo' }
#                              ^^^^^^^^^^^^^^^^
#                         This is the important part

这将加载名称directly from the service definition,而不会尝试输入call getDefaultName()