gpt4 book ai didi

php - Symfony 3,DI - 将服务添加到参数

转载 作者:行者123 更新时间:2023-12-03 01:05:50 28 4
gpt4 key购买 nike

我有这个代码

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 中我收到了此错误消息


[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The file "/ext/thing/app/config/services.yml" does not contain valid
YAML.


[Symfony\Component\Yaml\Exception\ParseException]
保留指示符“@”不能启动普通标量;您需要在第 14 行引用标量(靠近“arguments: [@repo.game]”)。

我的 /ext/thing/app/config/services.yml 文件中没有其他内容

最佳答案

引用 yaml section 中的升级指南:

Starting an unquoted string with @, `, |, or > leads to a ParseException.

因此尝试按如下方式修改您的配置:

 file.upload.listener:
class: AppBundle\Listener\FileUploadListener
arguments: ["@repo.game"]
tags:
- { name: "kernel.event_listener", event: "oneup_uploader.post_upload", method: "onUpload" }

希望这有帮助

关于php - Symfony 3,DI - 将服务添加到参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34069477/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com