function ConfigImporter::callAndReInjectIfNeeded
Executes a callable and re-injects services if the container was rebuilt.
Operations like module and theme installs can trigger a container rebuild. This method detects when that happens and automatically refreshes the services used by this importer.
Parameters
callable $callable: The callable to execute.
2 calls to ConfigImporter::callAndReInjectIfNeeded()
- ConfigImporter::importConfig in core/
lib/ Drupal/ Core/ Config/ ConfigImporter.php - Writes a configuration change from the source to the target storage.
- ConfigImporter::processExtension in core/
lib/ Drupal/ Core/ Config/ ConfigImporter.php - Processes an extension change.
File
-
core/
lib/ Drupal/ Core/ Config/ ConfigImporter.php, line 1170
Class
- ConfigImporter
- Defines a configuration importer.
Namespace
Drupal\Core\ConfigCode
protected function callAndReInjectIfNeeded(callable $callable) : void {
$container_id = spl_object_id(\Drupal::getContainer());
try {
$callable();
} finally {
if ($container_id !== spl_object_id(\Drupal::getContainer())) {
// When rebuilding the container,
// \Drupal\Core\DrupalKernel::initializeContainer() saves the hashes of
// the old container and passes them to the new one. So __sleep() will
// recognize the old services and then __wakeup() will restore them from
// the new container.
$this->__sleep();
$this->__wakeup();
$this->storageComparer
->__sleep();
$this->storageComparer
->__wakeup();
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.