diff --git a/DependencyInjection/Compiler/AddSpreadCompilerPass.php b/DependencyInjection/Compiler/AddSpreadCompilerPass.php index ba7ab70..5f83012 100644 --- a/DependencyInjection/Compiler/AddSpreadCompilerPass.php +++ b/DependencyInjection/Compiler/AddSpreadCompilerPass.php @@ -12,11 +12,20 @@ class AddSpreadCompilerPass implements CompilerPassInterface */ public function process(ContainerBuilder $container) { - $alias = $container->getAlias('spy_timeline.spread.deployer'); - $spreadDeployer = $container->getDefinition((string) $alias); + $alias = $container->getAlias('spy_timeline.spread.deployer'); + $spreadDeployer = $container->getDefinition((string) $alias); + $spreadByPriority = []; - foreach ($container->findTaggedServiceIds('spy_timeline.spread') as $id => $tags) { - $spreadDeployer->addMethodCall('addSpread', array($container->getDefinition($id))); + foreach ($container->findTaggedServiceIds('spy_timeline.spread') as $id => $options) { + $priority = array_key_exists('priority', $options[0]) ? $options[0]['priority'] : 0; + + $spreadByPriority[$priority][] = $container->getDefinition($id); + } + + krsort($spreadByPriority); + + foreach ($spreadByPriority as $spreads) { + $spreadDeployer->addMethodCall('addSpread', $spreads); } } }