CachePoolPrunerPass.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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\Cache\PruneableInterface;
  12. use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
  13. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Reference;
  16. /**
  17. * @author Rob Frawley 2nd <rmf@src.run>
  18. */
  19. class CachePoolPrunerPass implements CompilerPassInterface
  20. {
  21. public function process(ContainerBuilder $container): void
  22. {
  23. if (!$container->hasDefinition('console.command.cache_pool_prune')) {
  24. return;
  25. }
  26. $services = [];
  27. foreach ($container->findTaggedServiceIds('cache.pool') as $id => $tags) {
  28. if ($tags[0]['pruneable'] ?? $container->getReflectionClass($container->getDefinition($id)->getClass(), false)?->implementsInterface(PruneableInterface::class) ?? false) {
  29. $services[$tags[0]['name'] ?? $id] = new Reference($id);
  30. }
  31. }
  32. $container->getDefinition('console.command.cache_pool_prune')->replaceArgument(0, new IteratorArgument($services));
  33. }
  34. }