AddCacheWarmerPass.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\ContainerBuilder;
  4. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  5. use Symfony\Component\DependencyInjection\Reference;
  6. /*
  7. * This file is part of the Symfony framework.
  8. *
  9. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  10. *
  11. * This source file is subject to the MIT license that is bundled
  12. * with this source code in the file LICENSE.
  13. */
  14. /**
  15. * Registers the cache warmers.
  16. *
  17. * @author Fabien Potencier <fabien.potencier@symfony-project.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. // sort by priority and flatten
  35. krsort($warmers);
  36. $warmers = call_user_func_array('array_merge', $warmers);
  37. $container->getDefinition('cache_warmer')->setArgument(0, $warmers);
  38. if ('full' === $container->getParameter('kernel.cache_warmup')) {
  39. $container->getDefinition('cache_warmer')->addMethodCall('enableOptionalWarmers', array());
  40. }
  41. }
  42. }