protected function ModuleInstaller::removeCacheBins in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Extension/ModuleInstaller.php \Drupal\Core\Extension\ModuleInstaller::removeCacheBins()
- 9 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.
File
- core/
lib/ Drupal/ Core/ Extension/ ModuleInstaller.php, line 560
Class
- ModuleInstaller
- Default implementation of the module installer.
Namespace
Drupal\Core\ExtensionCode
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();
}
}
}