CachePoolClearerPass.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\Component\Cache\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. /**
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. */
  17. class CachePoolClearerPass implements CompilerPassInterface
  18. {
  19. private $cachePoolClearerTag;
  20. public function __construct(string $cachePoolClearerTag = 'cache.pool.clearer')
  21. {
  22. $this->cachePoolClearerTag = $cachePoolClearerTag;
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function process(ContainerBuilder $container)
  28. {
  29. $container->getParameterBag()->remove('cache.prefix.seed');
  30. foreach ($container->findTaggedServiceIds($this->cachePoolClearerTag) as $id => $attr) {
  31. $clearer = $container->getDefinition($id);
  32. $pools = [];
  33. foreach ($clearer->getArgument(0) as $name => $ref) {
  34. if ($container->hasDefinition($ref)) {
  35. $pools[$name] = new Reference($ref);
  36. }
  37. }
  38. $clearer->replaceArgument(0, $pools);
  39. }
  40. }
  41. }