AddCacheWarmerPass.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. * Registers the cache warmers.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class AddCacheWarmerPass implements CompilerPassInterface
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function process(ContainerBuilder $container)
  25. {
  26. if (!$container->hasDefinition('cache_warmer')) {
  27. return;
  28. }
  29. $warmers = array();
  30. foreach ($container->findTaggedServiceIds('kernel.cache_warmer') as $id => $attributes) {
  31. $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
  32. $warmers[$priority][] = new Reference($id);
  33. }
  34. if (empty($warmers)) {
  35. return;
  36. }
  37. // sort by priority and flatten
  38. krsort($warmers);
  39. $warmers = \call_user_func_array('array_merge', $warmers);
  40. $container->getDefinition('cache_warmer')->replaceArgument(0, $warmers);
  41. }
  42. }