Merge branch '2.8' into 3.2
* 2.8: [2.8] Prevent double registrations related to tag priorities Prevent double registrations related to tag priorities
This commit is contained in:
commit
79d2c0e2ca
@ -20,9 +20,9 @@ class PropertyInfoPassTest extends TestCase
|
|||||||
public function testServicesAreOrderedAccordingToPriority()
|
public function testServicesAreOrderedAccordingToPriority()
|
||||||
{
|
{
|
||||||
$services = array(
|
$services = array(
|
||||||
'n3' => array('tag' => array()),
|
'n3' => array(array()),
|
||||||
'n1' => array('tag' => array('priority' => 200)),
|
'n1' => array(array('priority' => 200)),
|
||||||
'n2' => array('tag' => array('priority' => 100)),
|
'n2' => array(array('priority' => 100)),
|
||||||
);
|
);
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -72,9 +72,9 @@ class SerializerPassTest extends TestCase
|
|||||||
public function testServicesAreOrderedAccordingToPriority()
|
public function testServicesAreOrderedAccordingToPriority()
|
||||||
{
|
{
|
||||||
$services = array(
|
$services = array(
|
||||||
'n3' => array('tag' => array()),
|
'n3' => array(array()),
|
||||||
'n1' => array('tag' => array('priority' => 200)),
|
'n1' => array(array('priority' => 200)),
|
||||||
'n2' => array('tag' => array('priority' => 100)),
|
'n2' => array(array('priority' => 100)),
|
||||||
);
|
);
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -29,27 +29,23 @@ class TwigLoaderPass implements CompilerPassInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// register additional template loaders
|
$prioritizedLoaders = array();
|
||||||
$loaderIds = $container->findTaggedServiceIds('twig.loader');
|
$found = 0;
|
||||||
|
|
||||||
if (count($loaderIds) === 0) {
|
foreach ($container->findTaggedServiceIds('twig.loader') as $id => $attributes) {
|
||||||
|
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
|
||||||
|
$prioritizedLoaders[$priority][] = $id;
|
||||||
|
++$found;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$found) {
|
||||||
throw new LogicException('No twig loaders found. You need to tag at least one loader with "twig.loader"');
|
throw new LogicException('No twig loaders found. You need to tag at least one loader with "twig.loader"');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($loaderIds) === 1) {
|
if (1 === $found) {
|
||||||
$container->setAlias('twig.loader', key($loaderIds));
|
$container->setAlias('twig.loader', $id);
|
||||||
} else {
|
} else {
|
||||||
$chainLoader = $container->getDefinition('twig.loader.chain');
|
$chainLoader = $container->getDefinition('twig.loader.chain');
|
||||||
|
|
||||||
$prioritizedLoaders = array();
|
|
||||||
|
|
||||||
foreach ($loaderIds as $id => $tags) {
|
|
||||||
foreach ($tags as $tag) {
|
|
||||||
$priority = isset($tag['priority']) ? $tag['priority'] : 0;
|
|
||||||
$prioritizedLoaders[$priority][] = $id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
krsort($prioritizedLoaders);
|
krsort($prioritizedLoaders);
|
||||||
|
|
||||||
foreach ($prioritizedLoaders as $loaders) {
|
foreach ($prioritizedLoaders as $loaders) {
|
||||||
|
Reference in New Issue
Block a user