8000 Prevent double registrations related to tag priorities by nicolas-grekas · Pull Request #22396 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Prevent double registrations related to tag priorities #22396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ private function findAndSortTaggedServices($tagName, ContainerBuilder $container
}

$sortedServices = array();
foreach ($services as $serviceId => $tags) {
foreach ($tags as $tag) {
$priority = isset($tag['priority']) ? $tag['priority'] : 0;
$sortedServices[$priority][] = new Reference($serviceId);
}
foreach ($services as $serviceId => $attributes) {
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
$sortedServices[$priority][] = new Reference($serviceId);
}

krsort($sortedServices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public function testThrowExceptionWhenNoEncoders()
public function testServicesAreOrderedAccordingToPriority()
{
$services = array(
'n3' => array('tag' => array()),
'n1' => array('tag' => array('priority' => 200)),
'n2' => array('tag' => array('priority' => 100)),
'n3' => array(array()),
'n1' => array(array('priority' => 200)),
'n2' => array(array('priority' => 100)),
);

$expected = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,23 @@ public function process(ContainerBuilder $container)
return;
}

// register additional template loaders
$loaderIds = $container->findTaggedServiceIds('twig.loader');
$prioritizedLoaders = array();
$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"');
}

if (count($loaderIds) === 1) {
$container->setAlias('twig.loader', key($loaderIds));
if (1 === $found) {
$container->setAlias('twig.loader', $id);
} else {
$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);

foreach ($prioritizedLoaders as $loaders) {
Expand Down
0