php - 在 symfony 5 中创建命令作为服务
问题描述
我正在尝试将命令类注册为 Symfony 中的服务。当我运行 bin/console 时,出现以下错误:
In App_KernelDevDebugContainer.php line 644:
Attempted to load class "Runner" from namespace "App\Command\Circuit".
Did you forget a "use" statement for another namespace?
这是我注册服务的方式:
services:
App\Command\Circuit\Runner:
tags:
- { name: 'console.command', command: 'run' }
这就是命令类的样子:
namespace App\Command\Circuit;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Runner extends Command
{
protected function configure()
{
$this
->setName('run');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$time = time();
file_put_contents("{$time}.txt", 'test');
}
}
我按照symfony 教程进行操作,但我确定有些东西我忘了连接这个服务。
解决方案
推荐阅读
- spring-boot - 带有 vaadin13 和 wildfly NoClassDefFoundError 的 Spring-boot
- redhat - 如何在redhat ubi8/ubi-minimal中安装ps
- reactjs - Material-UI 如何将自定义 Snackbar 的 TransitionComponent 更改为 Slide
- pycharm - 在两个不同的环境中使用 PyCharm 项目
- node.js - Heroku 生产服务器加密和本地解密失败
- python - 如何在 Python 37 中将 Drive API 与标准 Google App Engine 的凭据一起使用?
- c - C:通过 TCP 服务器和客户端套接字的文件传输不完整
- c++ - QProcess::execute 环境变量扩展字符串
- r - 如何对多个 .csv 文件(145 行 140 列的网格数据“单元格”)求和以获得相同维度的 csv 文件
- sql - 通过直接 SQL 注入将数组插入表中