Symfony 3, DI - 将服务添加到参数 [英] Symfony 3, DI - Add service to argument
本文介绍了Symfony 3, DI - 将服务添加到参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码
services:
repo.game:
class: Doctrine\ORM\EntityRepository
factory_service: doctrine.orm.default_entity_manager
factory_method: getRepository
arguments:
- AppBundle\Entity\Game
file.upload.listener:
class: AppBundle\Listener\FileUploadListener
arguments: [@repo.game]
tags:
- { name: "kernel.event_listener", event: "oneup_uploader.post_upload", method: "onUpload" }
这在 <= 2.8 中运行良好,但在 3.0 中我收到此错误消息
This worked fine in <= 2.8, but here in 3.0 I got this error message
<代码>[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]文件/ext/thing/app/config/services.yml"不包含有效YAML.
<代码>[Symfony\Component\Yaml\Exception\ParseException]保留指示符@"不能开始一个普通的标量;您需要引用第 14 行的标量(靠近参数:[@repo.game]").
我的 /ext/thing/app/config/services.yml
文件中没有其他内容
There is nothing else in my /ext/thing/app/config/services.yml
file
推荐答案
参考yaml 部分:
以@、`、| 或 > 开头的未加引号的字符串会导致解析异常.
Starting an unquoted string with @, `, |, or > leads to a ParseException.
所以尝试修改你的配置如下:
So try to modify your configuration as follow:
file.upload.listener:
class: AppBundle\Listener\FileUploadListener
arguments: ["@repo.game"]
tags:
- { name: "kernel.event_listener", event: "oneup_uploader.post_upload", method: "onUpload" }
希望对您有帮助
这篇关于Symfony 3, DI - 将服务添加到参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文