基於托馬斯的回答
$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
}
當然事件是基於標籤和只用實例或抽象類(如果方法您正在搜索的工作原理在後一種情況下是抽象的)
您是否嘗試過使用抽象服務?在這種情況下,你可以定義只在你的父服務中的所有子服務的集合將繼承此 –
你能鏈接到我嗎? –