ListCacheBinsPass.php 1.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<?php

/**
 * @file
 * Contains \Drupal\Core\Cache\ListCacheBinsPass.
 */

namespace Drupal\Core\Cache;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
 * Adds cache_bins parameter to the container.
 */
class ListCacheBinsPass implements CompilerPassInterface {

  /**
   * Implements CompilerPassInterface::process().
   *
   * Collects the cache bins into the cache_bins parameter.
   */
  public function process(ContainerBuilder $container) {
    $cache_bins = array();
25
    $cache_default_bin_backends = array();
26
    foreach ($container->findTaggedServiceIds('cache.bin') as $id => $attributes) {
27 28 29 30 31
      $bin = substr($id, strpos($id, '.') + 1);
      $cache_bins[$id] = $bin;
      if (isset($attributes[0]['default_backend'])) {
        $cache_default_bin_backends[$bin] = $attributes[0]['default_backend'];
      }
32 33
    }
    $container->setParameter('cache_bins', $cache_bins);
34
    $container->setParameter('cache_default_bin_backends', $cache_default_bin_backends);
35 36
  }
}