function ModuleInstaller::removeCacheBins

Same name in other branches
  1. 9 core/lib/Drupal/Core/Extension/ModuleInstaller.php \Drupal\Core\Extension\ModuleInstaller::removeCacheBins()
  2. 8.9.x core/lib/Drupal/Core/Extension/ModuleInstaller.php \Drupal\Core\Extension\ModuleInstaller::removeCacheBins()
  3. 11.x core/lib/Drupal/Core/Extension/ModuleInstaller.php \Drupal\Core\Extension\ModuleInstaller::removeCacheBins()

Helper method for removing all cache bins registered by a given module.

Parameters

string $module: The name of the module for which to remove all registered cache bins.

1 call to ModuleInstaller::removeCacheBins()
ModuleInstaller::uninstall in core/lib/Drupal/Core/Extension/ModuleInstaller.php

File

core/lib/Drupal/Core/Extension/ModuleInstaller.php, line 580

Class

ModuleInstaller
Default implementation of the module installer.

Namespace

Drupal\Core\Extension

Code

protected function removeCacheBins($module) {
    $service_yaml_file = \Drupal::service('extension.list.module')->getPath($module) . "/{$module}.services.yml";
    if (!file_exists($service_yaml_file)) {
        return;
    }
    $definitions = Yaml::decode(file_get_contents($service_yaml_file));
    $cache_bin_services = array_filter($definitions['services'] ?? [], function ($definition) {
        $tags = $definition['tags'] ?? [];
        foreach ($tags as $tag) {
            if (isset($tag['name']) && $tag['name'] == 'cache.bin') {
                return TRUE;
            }
        }
        return FALSE;
    });
    foreach (array_keys($cache_bin_services) as $service_id) {
        $backend = $this->kernel
            ->getContainer()
            ->get($service_id);
        if ($backend instanceof CacheBackendInterface) {
            $backend->removeBin();
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.