You are here

class SupercacheServiceProvider in Supercache 2.0.x

Same name and namespace in other branches
  1. 8 src/SupercacheServiceProvider.php \Drupal\supercache\SupercacheServiceProvider

Hard overrides some of core services with their couchbase implementation.

Hierarchy

Expanded class hierarchy of SupercacheServiceProvider

File

src/SupercacheServiceProvider.php, line 21

Namespace

Drupal\supercache
View source
class SupercacheServiceProvider implements ServiceProviderInterface {

  /**
   * {@inheritdoc}
   */
  public function register(ContainerBuilder $container) {

    // Override the default chained fast backend.
    $definition = $container
      ->getDefinition('cache.backend.chainedfast');
    if ($definition
      ->getClass() == ChainedFastBackendFactory::class) {
      $couchbase_definition = $container
        ->getDefinition('cache.backend.superchainedfast');
      $definition
        ->setClass($couchbase_definition
        ->getClass());
      $definition
        ->setArguments($couchbase_definition
        ->getArguments());
      $definition
        ->setTags($couchbase_definition
        ->getTags());
    }

    // Override the tag checksum invalidator.
    $definition = $container
      ->getDefinition('cache_tags.invalidator.checksum');
    if ($definition
      ->getClass() == DatabaseCacheTagsChecksum::class) {
      $couchbase_definition = $container
        ->getDefinition('cache_tags.invalidator.checksum.supercache');
      $definition
        ->setClass($couchbase_definition
        ->getClass());
      $definition
        ->setArguments($couchbase_definition
        ->getArguments());
      $definition
        ->setTags($couchbase_definition
        ->getTags());
    }

    // Override the default keyvalue store.
    $param = $container
      ->getParameter('factory.keyvalue');
    if ($param['default'] == 'keyvalue.database') {
      $param['default'] = 'keyvalue.supercache';
      $container
        ->setParameter('factory.keyvalue', $param);
    }

    // Override the default keyvalue expirable store.
    // We use 'default' and 'keyvalue_expirable_default' due
    // to a bug in the core service.
    $param = $container
      ->getParameter('factory.keyvalue.expirable');
    if (isset($param['default']) && $param['default'] == 'keyvalue.expirable.database' || isset($param['keyvalue_expirable_default']) && $param['keyvalue_expirable_default'] == 'keyvalue.expirable.database') {
      $param['default'] = 'keyvalue.expirable.supercache';
      $param['keyvalue_expirable_default'] = 'keyvalue.expirable.supercache';
      $container
        ->setParameter('factory.keyvalue.expirable', $param);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SupercacheServiceProvider::register public function Registers services to the container. Overrides ServiceProviderInterface::register