Symfony 命令在生产环境中有一个空名称

Symfony Command have an empty name in production environement

我正在使用 Symfony2 Command,当我在 prod 环境中尝试 运行 命令时出现错误,但它在 [=15] 中运行良好=]:

如果我 运行 一切都很好 :

php app/console mycommand:start

当我运行

php app/console mycommand:start --env=prod

我收到这个错误:

[LogicException]                                                                               
The command defined in "NameSpace\Of\MyClassCommand" cannot have an empty name.

命令定义:

services:
  my_service.command:
      class: NameSpace\Of\MyClassCommand
      arguments:
        name: mycommand:start
      tags:
        - { name: console.command }

命令:

class MyClassCommand extends Command
{

    /**
    * @param InputInterface $input
    * @param OutputInterface $output
    */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // logic
    }

    ...
}

您可能会注意到,我没有重载 __constructconfigure 方法。我试过了,但没有任何改变。如果我清理缓存也是一样。

有没有人知道 proddev 环境之间的区别是什么导致了这个问题?

谢谢

我终于找到了解决方案,Ruslan 你是对的:清除缓存。 但是我不得不手动核对缓存文件夹,cache:clear 命令是不够的。

清除缓存对我不起作用。我需要将 base class 声明为 abstract class 以提示 Symfony 不要将其注册为命令。

abstract class BaseCommand {
    ...
}