You can modify the container here before it is dumped to PHP code.
@api
ContainerBuilder $container:
Overrides CompilerPassInterface::process
public function process(ContainerBuilder $container) {
if (!$container
->hasDefinition('event_dispatcher')) {
return;
}
$definition = $container
->getDefinition('event_dispatcher');
foreach ($container
->findTaggedServiceIds('event_subscriber') as $id => $attributes) {
// We must assume that the class value has been correcly filled, even if the service is created by a factory
$class = $container
->getDefinition($id)
->getClass();
$refClass = new ReflectionClass($class);
$interface = 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface';
if (!$refClass
->implementsInterface($interface)) {
throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
}
$definition
->addMethodCall('addSubscriberService', array(
$id,
$class,
));
}
}