8000 Prevent double registrations related to tag priorities · symfony/symfony@384b92d · GitHub
[go: up one dir, main page]

Skip to content

Commit 384b92d

Browse files
Prevent double registrations related to tag priorities
1 parent f478161 commit 384b92d

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/Symfony/Bundle/FrameworkBundle/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);

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

Lines 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