我定义了以下服务:
my_project.widget_listing_content_resolver:
class: MyProject\Widget\ListingBundle\Resolver\WidgetListingContentResolver
arguments:
- "@router"
tags:
- { name: my_project.widget_content_resolver, alias: Listing }
我想声明此服务的别名,使用不同的标记:
my_project.widget_domain_operations_content_resolver:
alias: my_project.widget_listing_content_resolver
tags:
- { name: my_project.widget_content_resolver, alias: DomainOperations }
但在我的ContentResolverChain中,服务别名" DomainOperations"不在场。有办法解决这个问题吗?
编辑: 我尝试了以下配置:
my_project.widget_listing_content_resolver:
class: MyProject\Widget\ListingBundle\Resolver\WidgetListingContentResolver
arguments:
- "@router"
tags:
- { name: my_project.widget_content_resolver, alias: Listing }
- { name: my_project.widget_content_resolver, alias: DomainOperations }
结果是" my_project.widget_listing_content_resolver" service仅标记为" Listing"。我现在的问题是:"如何标记具有多个标记别名的服务"
答案 0 :(得分:0)
我找到了解决这个问题的方法。服务别名被标记为espected,但我的CompilerPass没有读取附加标记:
这是错误的CompilerPass:
$taggedServices = $container->findTaggedServiceIds(
'my_project.widget_content_resolver'
);
foreach ($taggedServices as $id => $attributes) {
$definition->addMethodCall(
'addResolver',
array($attributes[0]['alias'], new Reference($id))
);
}
如您所见,它只找到了第一个别名($ attributes [0])
我不得不将其更改为:
$taggedServices = $container->findTaggedServiceIds(
'my_project.widget_content_resolver'
);
foreach ($taggedServices as $id => $attributes) {
foreach ($attributes as $attribute) {
$definition->addMethodCall(
'addResolver',
array($attribute['alias'], new Reference($id))
);
}
}