基于托马斯的回答
$taggedServices = $container->findTaggedServiceIds('your_tag');
foreach ($taggedServices as $id => $tags) {
$service = $container->findDefinition($id);
if (!is_callable($service, 'yourMethodName') {
continue;
// or raise exception if you need
}
$service->addMethodCall(...); //whatever
}
另一种方式是
$taggedServices = $container->findTaggedServiceIds('your_tag');
foreach ($taggedServices as $id => $tags) {
$service = $container->findDefinition($id);
if (!$service instance YourInterface) {
continue;
// or raise exception if you need
}
$service->addMethodCall(...); //whatever
}
当然事件是基于标签和只用实例或抽象类(如果方法您正在搜索的工作原理在后一种情况下是抽象的)
您是否尝试过使用抽象服务?在这种情况下,你可以定义只在你的父服务中的所有子服务的集合将继承此 –
你能链接到我吗? –