Skip to content

Commit 5d3ff12

Browse files
committed
bug #22396 Prevent double registrations related to tag priorities (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- Prevent double registrations related to tag priorities | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - The current logic is inconsistent, and allows the same id to be used several times. This makes the first explicit priority to always win. Commits ------- 6764dcdf39 Prevent double registrations related to tag priorities
2 parents 637f9f8 + 60f5bdb commit 5d3ff12

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

DependencyInjection/Compiler/SerializerPass.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ private function findAndSortTaggedServices($tagName, ContainerBuilder $container
4747
}
4848

4949
$sortedServices = array();
50-
foreach ($services as $serviceId => $tags) {
51-
foreach ($tags as $tag) {
52-
$priority = isset($tag['priority']) ? $tag['priority'] : 0;
53-
$sortedServices[$priority][] = new Reference($serviceId);
54-
}
50+
foreach ($services as $serviceId => $attributes) {
51+
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
52+
$sortedServices[$priority][] = new Reference($serviceId);
5553
}
5654

5755
krsort($sortedServices);

Tests/DependencyInjection/Compiler/SerializerPassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ public function testThrowExceptionWhenNoEncoders()
7272
public function testServicesAreOrderedAccordingToPriority()
7373
{
7474
$services = array(
75-
'n3' => array('tag' => array()),
76-
'n1' => array('tag' => array('priority' => 200)),
77-
'n2' => array('tag' => array('priority' => 100)),
75+
'n3' => array(array()),
76+
'n1' => array(array('priority' => 200)),
77+
'n2' => array(array('priority' => 100)),
7878
);
7979

8080
$expected = array(

0 commit comments

Comments
 (0)