class RecipeOverrideConfigStorage

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Recipe/RecipeOverrideConfigStorage.php \Drupal\Core\Recipe\RecipeOverrideConfigStorage

Wraps a config storage to allow recipe provided configuration to override it.

@internal This API is experimental.

Hierarchy

Expanded class hierarchy of RecipeOverrideConfigStorage

File

core/lib/Drupal/Core/Recipe/RecipeOverrideConfigStorage.php, line 15

Namespace

Drupal\Core\Recipe
View source
final class RecipeOverrideConfigStorage implements StorageInterface {
  
  /**
   * @param \Drupal\Core\Config\StorageInterface $recipeStorage
   *   The recipe's configuration storage.
   * @param \Drupal\Core\Config\StorageInterface $wrappedStorage
   *   The storage to override.
   * @param string $collection
   *   (optional) The collection to store configuration in. Defaults to the
   *   default collection.
   */
  public function __construct(protected readonly StorageInterface $recipeStorage, protected readonly StorageInterface $wrappedStorage, protected readonly string $collection = StorageInterface::DEFAULT_COLLECTION) {
  }
  
  /**
   * {@inheritdoc}
   */
  public function exists($name) : bool {
    return $this->wrappedStorage
      ->exists($name);
  }
  
  /**
   * {@inheritdoc}
   */
  public function read($name) : array|bool {
    if ($this->wrappedStorage
      ->exists($name) && $this->recipeStorage
      ->exists($name)) {
      return $this->recipeStorage
        ->read($name);
    }
    return $this->wrappedStorage
      ->read($name);
  }
  
  /**
   * {@inheritdoc}
   */
  public function readMultiple(array $names) : array {
    $data = $this->wrappedStorage
      ->readMultiple($names);
    foreach ($data as $name => $value) {
      if ($this->recipeStorage
        ->exists($name)) {
        $data[$name] = $this->recipeStorage
          ->read($name);
      }
    }
    return $data;
  }
  
  /**
   * {@inheritdoc}
   */
  public function write($name, array $data) : bool {
    throw new \BadMethodCallException();
  }
  
  /**
   * {@inheritdoc}
   */
  public function delete($name) : bool {
    throw new \BadMethodCallException();
  }
  
  /**
   * {@inheritdoc}
   */
  public function rename($name, $new_name) : bool {
    throw new \BadMethodCallException();
  }
  
  /**
   * {@inheritdoc}
   */
  public function encode($data) : string {
    return $this->wrappedStorage
      ->encode($data);
  }
  
  /**
   * {@inheritdoc}
   */
  public function decode($raw) : array {
    return $this->wrappedStorage
      ->decode($raw);
  }
  
  /**
   * {@inheritdoc}
   */
  public function listAll($prefix = '') : array {
    return $this->wrappedStorage
      ->listAll($prefix);
  }
  
  /**
   * {@inheritdoc}
   */
  public function deleteAll($prefix = '') : bool {
    throw new \BadMethodCallException();
  }
  
  /**
   * {@inheritdoc}
   */
  public function createCollection($collection) : static {
    return new static($this->recipeStorage
      ->createCollection($collection), $this->wrappedStorage
      ->createCollection($collection), $collection);
  }
  
  /**
   * {@inheritdoc}
   */
  public function getAllCollectionNames() : array {
    return $this->wrappedStorage
      ->getAllCollectionNames();
  }
  
  /**
   * {@inheritdoc}
   */
  public function getCollectionName() : string {
    return $this->collection;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
RecipeOverrideConfigStorage::createCollection public function Creates a collection on the storage. Overrides StorageInterface::createCollection
RecipeOverrideConfigStorage::decode public function Decodes configuration data from the storage-specific format. Overrides StorageInterface::decode
RecipeOverrideConfigStorage::delete public function Deletes a configuration object from the storage. Overrides StorageInterface::delete
RecipeOverrideConfigStorage::deleteAll public function Deletes configuration objects whose names start with a given prefix. Overrides StorageInterface::deleteAll
RecipeOverrideConfigStorage::encode public function Encodes configuration data into the storage-specific format. Overrides StorageInterface::encode
RecipeOverrideConfigStorage::exists public function Returns whether a configuration object exists. Overrides StorageInterface::exists
RecipeOverrideConfigStorage::getAllCollectionNames public function Gets the existing collections. Overrides StorageInterface::getAllCollectionNames
RecipeOverrideConfigStorage::getCollectionName public function Gets the name of the current collection the storage is using. Overrides StorageInterface::getCollectionName
RecipeOverrideConfigStorage::listAll public function Gets configuration object names starting with a given prefix. Overrides StorageInterface::listAll
RecipeOverrideConfigStorage::read public function Reads configuration data from the storage. Overrides StorageInterface::read
RecipeOverrideConfigStorage::readMultiple public function Reads configuration data from the storage. Overrides StorageInterface::readMultiple
RecipeOverrideConfigStorage::rename public function Renames a configuration object in the storage. Overrides StorageInterface::rename
RecipeOverrideConfigStorage::write public function Writes configuration data to the storage. Overrides StorageInterface::write
RecipeOverrideConfigStorage::__construct public function
StorageInterface::DEFAULT_COLLECTION constant The default collection name.

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