function StorageComparer::__construct

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Config/StorageComparer.php \Drupal\Core\Config\StorageComparer::__construct()
  2. 8.9.x core/lib/Drupal/Core/Config/StorageComparer.php \Drupal\Core\Config\StorageComparer::__construct()
  3. 10 core/lib/Drupal/Core/Config/StorageComparer.php \Drupal\Core\Config\StorageComparer::__construct()

Constructs the Configuration storage comparer.

Parameters

\Drupal\Core\Config\StorageInterface $source_storage: Storage object used to read configuration.

\Drupal\Core\Config\StorageInterface $target_storage: Storage object used to write configuration.

File

core/lib/Drupal/Core/Config/StorageComparer.php, line 109

Class

StorageComparer
Defines a config storage comparer.

Namespace

Drupal\Core\Config

Code

public function __construct(StorageInterface $source_storage, StorageInterface $target_storage) {
    if ($source_storage->getCollectionName() !== StorageInterface::DEFAULT_COLLECTION) {
        $source_storage = $source_storage->createCollection(StorageInterface::DEFAULT_COLLECTION);
    }
    if ($target_storage->getCollectionName() !== StorageInterface::DEFAULT_COLLECTION) {
        $target_storage = $target_storage->createCollection(StorageInterface::DEFAULT_COLLECTION);
    }
    $time = \Drupal::hasService(TimeInterface::class) ? \Drupal::service(TimeInterface::class) : new Time();
    if ($source_storage instanceof FileStorage) {
        // FileStorage has its own static cache so that multiple reads of the
        // same raw configuration object are not costly.
        $this->sourceCacheStorage = new NullBackend('storage_comparer');
        $this->sourceStorage = $source_storage;
    }
    else {
        // Wrap the source storage in a static cache so that multiple reads of the
        // same raw configuration object are not costly.
        $this->sourceCacheStorage = new MemoryBackend($time);
        $this->sourceStorage = new CachedStorage($source_storage, $this->sourceCacheStorage);
    }
    $this->targetCacheStorage = new MemoryBackend($time);
    $this->targetStorage = $target_storage;
    $this->changelist[StorageInterface::DEFAULT_COLLECTION] = $this->getEmptyChangelist();
}

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