function RecipeConfigStorageWrapper::createStorageFromArray

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Recipe/RecipeConfigStorageWrapper.php \Drupal\Core\Recipe\RecipeConfigStorageWrapper::createStorageFromArray()

Creates a single config storage for an array of storages.

If the same configuration is contained in multiple storages then the version returned is from the first storage supplied in the $storages array.

Parameters

\Drupal\Core\Config\StorageInterface[] $storages: An array of storages to merge into a single storage.

Return value

\Drupal\Core\Config\StorageInterface A config storage that represents a merge of all the provided storages.

4 calls to RecipeConfigStorageWrapper::createStorageFromArray()
ConfigConfigurator::getConfigStorage in core/lib/Drupal/Core/Recipe/ConfigConfigurator.php
Gets a config storage object for reading config from the recipe.
RecipeConfigStorageWrapperTest::testMultipleStorages in core/tests/Drupal/Tests/Core/Recipe/RecipeConfigStorageWrapperTest.php
Validate that multiple storages return underlying values correctly.
RecipeConfigStorageWrapperTest::testNullStorage in core/tests/Drupal/Tests/Core/Recipe/RecipeConfigStorageWrapperTest.php
Validate that an empty set of storage backends returns null storage.
RecipeConfigStorageWrapperTest::testSingleStorage in core/tests/Drupal/Tests/Core/Recipe/RecipeConfigStorageWrapperTest.php
Validate that a single storage returns exactly the same instance.

File

core/lib/Drupal/Core/Recipe/RecipeConfigStorageWrapper.php, line 46

Class

RecipeConfigStorageWrapper
Merges two storages together.

Namespace

Drupal\Core\Recipe

Code

public static function createStorageFromArray(array $storages) : StorageInterface {
  // If storages is empty use the NullStorage to represent an empty storage.
  if (empty($storages)) {
    return new NullStorage();
  }
  // When there is only one storage there is no point wrapping it.
  if (count($storages) === 1) {
    return reset($storages);
  }
  // Reduce all the storages to a single RecipeConfigStorageWrapper object.
  // The storages are prioritized in the order they are added to $storages.
  return array_reduce($storages, fn(StorageInterface $carry, StorageInterface $storage) => new static($carry, $storage), new static(array_shift($storages), array_shift($storages)));
}

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