Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 92eb9e1

Browse filesBrowse 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 ------- 6764dcd Prevent double registrations related to tag priorities
2 parents cff1842 + 6764dcd commit 92eb9e1
Copy full SHA for 92eb9e1

File tree

Expand file treeCollapse file tree

3 files changed

+17
-23
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-23
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SerializerPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SerializerPass.php
+3-5Lines 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);

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SerializerPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SerializerPassTest.php
+3-3Lines 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(

‎src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/TwigLoaderPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/TwigLoaderPass.php
+11-15Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,23 @@ public function process(ContainerBuilder $container)
2929
return;
3030
}
3131

32-
// register additional template loaders
33-
$loaderIds = $container->findTaggedServiceIds('twig.loader');
32+
$prioritizedLoaders = array();
33+
$found = 0;
3434

35-
if (count($loaderIds) === 0) {
35+
foreach ($container->findTaggedServiceIds('twig.loader') as $id => $attributes) {
36+
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
37+
$prioritizedLoaders[$priority][] = $id;
38+
++$found;
39+
}
40+
41+
if (!$found) {
3642
throw new LogicException('No twig loaders found. You need to tag at least one loader with "twig.loader"');
3743
}
3844

39-
if (count($loaderIds) === 1) {
40-
$container->setAlias('twig.loader', key($loaderIds));
45+
if (1 === $found) {
46+
$container->setAlias('twig.loader', $id);
4147
} else {
4248
$chainLoader = $container->getDefinition('twig.loader.chain');
43-
44-
$prioritizedLoaders = array();
45-
46-
foreach ($loaderIds as $id => $tags) {
47-
foreach ($tags as $tag) {
48-
$priority = isset($tag['priority']) ? $tag['priority'] : 0;
49-
$prioritizedLoaders[$priority][] = $id;
50-
}
51-
}
52-
5349
krsort($prioritizedLoaders);
5450

5551
foreach ($prioritizedLoaders as $loaders) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.