8000 Implemented the SplPriorityQueue · symfony/symfony@e5ca7c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit e5ca7c5

Browse files
Iltar van der Berglinaori
Iltar van der Berg
authored andcommitted
Implemented the SplPriorityQueue
1 parent 2d25573 commit e5ca7c5

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,15 @@ private function findAndSortTaggedServices($tagName, ContainerBuilder $container
3333
{
3434
$services = $container->findTaggedServiceIds($tagName);
3535

36-
$sortedServices = array();
36+
$queue = new \SplPriorityQueue();
37+
3738
foreach ($services as $serviceId => $tags) {
3839
foreach ($tags as $attributes) {
3940
$priority = isset($attributes['priority']) ? $attributes['priority'] : 0;
40-
$sortedServices[$priority][] = new Reference($serviceId);
41+
$queue->insert(new Reference($serviceId), $priority * -1);
4142
}
4243
}
4344

44-
if (empty($sortedServices)) {
45-
return array();
46-
}
47-
48-
krsort($sortedServices);
49-
50-
// Flatten the array
51-
return call_user_func_array('array_merge', $sortedServices);
45+
return iterator_to_array($queue);
5246
}
5347
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTrait.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ class PriorityTaggedServiceTraitTest extends \PHPUnit_Framework_TestCase
2020
public function testThatCacheWarmersAreProcessedInPriorityOrder()
2121
{
2222
$services = array(
23-
'my_service1' => array(0 => array('priority' => 100)),
24-
'my_service2' => array(0 => array('priority' => 200)),
25-
'my_service3' => array(0 => array('priority' => -500)),
26-
'my_service4' => array(0 => array()),
23+
'my_service1' => array(array('priority' => 100)),
24+
'my_service2' => array(array('priority' => 200)),
25+
'my_service3' => array(array('priority' => -500)),
26+
'my_service4' => array(array()),
27+
'my_service5' => array(array()),
28+
'my_service6' => array(array('priority' => -500)),
29+
'my_service7' => array(array('priority' => -499)),
30+
'my_service8' => array(array('priority' => 1)),
2731
);
2832

2933
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
@@ -48,8 +52,12 @@ public function testThatCacheWarmersAreProcessedInPriorityOrder()
4852
->with(0, array(
4953
new Reference('my_service2'),
5054
new Reference('my_service1'),
55+
new Reference('my_service8'),
5156
new Reference('my_service4'),
57+
new Reference('my_service5'),
58+
new Reference('my_service7'),
5259
new Reference('my_service3'),
60+
new Reference('my_service6'),
5361
));
5462

5563
(new PriorityTaggedServiceTraitImplementation())->test('my_custom_tag', $container);

0 commit comments

Comments
 (0)
0