ListCacheBinsPass.php 994 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Drupal\Core\Cache;
  3. use Symfony\Component\DependencyInjection\ContainerBuilder;
  4. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  5. /**
  6. * Adds cache_bins parameter to the container.
  7. */
  8. class ListCacheBinsPass implements CompilerPassInterface {
  9. /**
  10. * Implements CompilerPassInterface::process().
  11. *
  12. * Collects the cache bins into the cache_bins parameter.
  13. */
  14. public function process(ContainerBuilder $container) {
  15. $cache_bins = [];
  16. $cache_default_bin_backends = [];
  17. foreach ($container->findTaggedServiceIds('cache.bin') as $id => $attributes) {
  18. $bin = substr($id, strpos($id, '.') + 1);
  19. $cache_bins[$id] = $bin;
  20. if (isset($attributes[0]['default_backend'])) {
  21. $cache_default_bin_backends[$bin] = $attributes[0]['default_backend'];
  22. }
  23. }
  24. $container->setParameter('cache_bins', $cache_bins);
  25. $container->setParameter('cache_default_bin_backends', $cache_default_bin_backends);
  26. }
  27. }