CachePoolClearerPass.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. if (0 < \func_num_args()) {
  23. trigger_deprecation('symfony/cache', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
  24. }
  25. $this->cachePoolClearerTag = $cachePoolClearerTag;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function process(ContainerBuilder $container)
  31. {
  32. $container->getParameterBag()->remove('cache.prefix.seed');
  33. foreach ($container->findTaggedServiceIds($this->cachePoolClearerTag) as $id => $attr) {
  34. $clearer = $container->getDefinition($id);
  35. $pools = [];
  36. foreach ($clearer->getArgument(0) as $name => $ref) {
  37. if ($container->hasDefinition($ref)) {
  38. $pools[$name] = new Reference($ref);
  39. }
  40. }
  41. $clearer->replaceArgument(0, $pools);
  42. }
  43. }
  44. }