4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Compiler;
14 use Symfony\Component\DependencyInjection\ContainerBuilder;
15 use Symfony\Component\DependencyInjection\Reference;
18 * Trait that allows a generic method to find and sort service by priority option in the tag.
20 * @author Iltar van der Berg <kjarli@gmail.com>
22 trait PriorityTaggedServiceTrait
25 * Finds all services with the given tag name and order them by their priority.
27 * The order of additions must be respected for services having the same priority,
28 * and knowing that the \SplPriorityQueue class does not respect the FIFO method,
29 * we should not use that class.
31 * @see https://bugs.php.net/bug.php?id=53710
32 * @see https://bugs.php.net/bug.php?id=60926
34 * @param string $tagName
35 * @param ContainerBuilder $container
39 private function findAndSortTaggedServices($tagName, ContainerBuilder $container)
43 foreach ($container->findTaggedServiceIds($tagName, true) as $serviceId => $attributes) {
44 $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
45 $services[$priority][] = new Reference($serviceId);
50 $services = \call_user_func_array('array_merge', $services);