1 回答
TA贡献1834条经验 获得超8个赞
经过更多的研究和扫描 Symfony 的源代码后,我找到了一个适合我需要的解决方案:我手动创建了一个实例ArgumentResolver并使用它。
注意我的用例需要解析一个不是服务的对象,因此它不能像任何其他服务一样通过依赖注入机制来解析。我将其包含在我的答案中,因为它可能对其他人有用:
$resolvers = [];
array_push($resolvers, ...ArgumentResolver::getDefaultArgumentValueResolvers());
array_push($resolvers, new class implements ArgumentValueResolverInterface {
// implement the interface to resolve an argument with a specific type/name
});
$argument_resolver = new ArgumentResolver(new ArgumentMetadataFactory(), $resolvers);
// to use it:
$arguments = $argument_resolver->getArguments($request, [$datasource, 'query']);
$datasource->query(...$arguments);
我希望这对其他人有用。
我无法证明这是解决方案或最佳解决方案,但它似乎对我的用例有用。我欢迎其他人发表评论/回答,以便我们共同改进解决方案
- 1 回答
- 0 关注
- 75 浏览
添加回答
举报