php - 如何将带有 EntityManager 注入的 Symfony 5 命令添加到控制台应用程序
问题描述
我在命令构造函数中添加了注入 EntityManagerInterface
# Class MyCommand
public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
parent::__construct();
}
但我不明白如何将我的命令添加到应用程序,因为它现在有一个新参数
use Symfony\Component\Console\Application;
$app = new Application();
$app->add(new MyCommand($entityManager)); // where is $entityManager defined ?
如何获得定义的 $entityManager?或者我必须在某个地方定义它,因为它不能使用 Symfony 自动引导?
解决方案
推荐阅读
- regex - Ansible 正则表达式匹配字符串并提取行
- java - JDK 9.0.4 和 Derby 10.14.2 找不到创建的表
- angular - i18n 关于 Angular 7 中具有复数/选择的属性
- tfs - 如何启动由 TFS Release Agent 执行后不关闭的控制台程序
- mysql - 我可以比较同一个 MySQL 表 (SQL) 中的不同行吗
- ajax - 查询生成器中的存储类
- javascript - 将数组合并到 JavaScript 中的对象属性中
- html - 如何将数据从 HTML 传递到 NodeJS
- angular - 根据其他下拉选择动态显示下拉元素
- docker - 使用路由表创建容器