Symfony命令在生产环境中的名称为空

irlmq6kh  于 2023-10-24  发布在  其他
关注(0)|答案(3)|浏览(177)

我正在使用Symfony2 Command,当我尝试在prod环境中运行命令时出现错误,但它在dev中工作得很好:
一切都很好,如果我跑:
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环境之间的区别是什么,导致了这个问题?
谢谢你

9w11ddsr

9w11ddsr1#

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

abstract class BaseCommand {
    ...
}
cnwbcb6i

cnwbcb6i2#

我终于找到了解决办法,鲁斯兰你是对的:清除该高速缓存。但我不得不手动核攻击该高速缓存文件夹,cache:clear命令是不够的。

w80xi6nr

w80xi6nr3#

下面是Symfony 6中相同问题的答案。
如果命令被定义为...

#[AsCommand(name: 'app:export-code-table',description: 'Export code table to a CSV file')]
class ExportCodeTableCommand extends Command
{
  // ...
}

symfony console list产生...

[WARNING] Some commands could not be registered:                                                                       
                                                                                                                                                                                                                           
  The command defined in "App\Command\ExportCodeTableCommand" cannot have an empty name.

问题是代码缺少一个引用...

use Symfony\Component\Console\Attribute\AsCommand;

相关问题