You are here

public function SupercacheServiceProvider::register in Supercache 2.0.x

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

Registers services to the container.

Parameters

ContainerBuilder $container: The ContainerBuilder to register services to.

Overrides ServiceProviderInterface::register

File

src/SupercacheServiceProvider.php, line 25

Class

SupercacheServiceProvider
Hard overrides some of core services with their couchbase implementation.

Namespace

Drupal\supercache

Code

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);
  }
}