Php 找不到具有构造函数的Symfony命令

Php 找不到具有构造函数的Symfony命令,php,symfony,Php,Symfony,我正在努力使我的代码准备好更新到Symfony4。 为此,我想重构命令以获得私有服务。 我查阅了文档,必须在命令中添加一个构造函数。 当我这样做时,我不能使用该命令,因为它表示没有使用该名称的命令,而当我删除构造函数时,它正在工作 命令: class CorrectionReponseCommand extends Command { public function __construct(EntityManagerInterface $em) { $this-&

我正在努力使我的代码准备好更新到Symfony4。 为此,我想重构命令以获得私有服务。 我查阅了文档,必须在命令中添加一个构造函数。 当我这样做时,我不能使用该命令,因为它表示没有使用该名称的命令,而当我删除构造函数时,它正在工作

命令:

class CorrectionReponseCommand extends Command
{
    public function __construct(EntityManagerInterface $em)
    {
        $this->em = $em;

        parent::__construct();
    }

    protected function configure()
    {
        $this
            ->setName('correction:reponse')
            ->setDescription('Calcule les notes de chaque réponse.');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        ...
    }
}
services.yml:

services:
     _defaults:
        autowire: true
        autoconfigure: true
        public: false

     App\CorrectionReponseCommand:
        public: true
        tags:
           - { name: 'console.command', command: 'correction:response' }

如果您使用的是Symfony 4.x,则所有服务都是使用自动布线/自动配置创建的,默认情况下是私有的

您应该检查服务的配置文件,并将
public:true
显式或标记添加到命令定义中

# config/services.yaml
# ...

services:
    # ...

    App\CorrectionReponseCommand:
        # ...
        public: true
        tags:
            - { name: 'console.command', command: 'app:correction:response' }

更多信息。

我仍在使用Symfony 3.4。在myservices.yml中,我有这样一个选项:
\u默认值:autowire:true autoconfigure:true public:false
,因此,您应该显式地将其设置为public。您能给我们看一下您的服务定义文件吗?它正在使用您的配置。谢谢!我仍然在问自己一个问题:是否建议将命令用于公共服务?