Skip to content

Commit cd1d700

Browse files
GeoffroyRWhatsOn
authored andcommitted
Fix: Take service priority into account when registering providers in… (#1172)
* Fix: Take service priority into account when registering providers in compiler pass * FIx empty array when no providers are defined * Update RegisterProvidersPass.php
1 parent 488d588 commit cd1d700

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

DependencyInjection/Compiler/RegisterProvidersPass.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,18 @@ public function process(ContainerBuilder $container)
3030
$registry = $container->getDefinition('fos_elastica.provider_registry');
3131
$providers = $container->findTaggedServiceIds('fos_elastica.provider');
3232

33-
foreach ($providers as $providerId => $tags) {
33+
$providersByPriority = array();
34+
foreach ($providers as $id => $attributes) {
35+
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
36+
$providersByPriority[$priority][$id] = $attributes;
37+
}
38+
39+
if (!empty($providersByPriority)){
40+
krsort($providersByPriority);
41+
$providersByPriority = call_user_func_array('array_merge', $providersByPriority);
42+
}
43+
44+
foreach ($providersByPriority as $providerId => $tags) {
3445
$index = $type = null;
3546
$class = $container->getDefinition($providerId)->getClass();
3647

0 commit comments

Comments
 (0)