ConfigCachePass.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. /**
  15. * Adds services tagged config_cache.resource_checker to the config_cache_factory service, ordering them by priority.
  16. *
  17. * @author Matthias Pigulla <mp@webfactory.de>
  18. * @author Benjamin Klotz <bk@webfactory.de>
  19. */
  20. class ConfigCachePass implements CompilerPassInterface
  21. {
  22. public function process(ContainerBuilder $container)
  23. {
  24. $resourceCheckers = array();
  25. foreach ($container->findTaggedServiceIds('config_cache.resource_checker') as $id => $tags) {
  26. $priority = isset($tags[0]['priority']) ? $tags[0]['priority'] : 0;
  27. $resourceCheckers[$priority][] = new Reference($id);
  28. }
  29. if (empty($resourceCheckers)) {
  30. return;
  31. }
  32. // sort by priority and flatten
  33. krsort($resourceCheckers);
  34. $resourceCheckers = \call_user_func_array('array_merge', $resourceCheckers);
  35. $container->getDefinition('config_cache_factory')->replaceArgument(0, $resourceCheckers);
  36. }
  37. }