class ManagedStorage
Same name in other branches
- 9 core/lib/Drupal/Core/Config/ManagedStorage.php \Drupal\Core\Config\ManagedStorage
- 10 core/lib/Drupal/Core/Config/ManagedStorage.php \Drupal\Core\Config\ManagedStorage
- 11.x core/lib/Drupal/Core/Config/ManagedStorage.php \Drupal\Core\Config\ManagedStorage
The managed storage defers all the storage method calls to the manager.
The reason for deferring all the method calls is that the storage interface is the API but we potentially need to do an expensive transformation before the storage can be used so we can't do it in the constructor but we also don't know which method is called first.
This class is not meant to be extended and is final to make sure the assumptions that the storage is retrieved only once are upheld.
Hierarchy
- class \Drupal\Core\Config\ManagedStorage implements \Drupal\Core\Config\StorageInterface
Expanded class hierarchy of ManagedStorage
1 file declares its use of ManagedStorage
- ManagedStorageTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Config/ Storage/ ManagedStorageTest.php
1 string reference to 'ManagedStorage'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses ManagedStorage
File
-
core/
lib/ Drupal/ Core/ Config/ ManagedStorage.php, line 16
Namespace
Drupal\Core\ConfigView source
final class ManagedStorage implements StorageInterface {
/**
* The decorated storage.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $storage;
/**
* The storage manager to get the storage to decorate.
*
* @var \Drupal\Core\Config\StorageManagerInterface
*/
protected $manager;
/**
* ManagedStorage constructor.
*
* @param \Drupal\Core\Config\StorageManagerInterface $manager
* The storage manager.
*/
public function __construct(StorageManagerInterface $manager) {
$this->manager = $manager;
}
/**
* {@inheritdoc}
*/
public function exists($name) {
return $this->getStorage()
->exists($name);
}
/**
* {@inheritdoc}
*/
public function read($name) {
return $this->getStorage()
->read($name);
}
/**
* {@inheritdoc}
*/
public function readMultiple(array $names) {
return $this->getStorage()
->readMultiple($names);
}
/**
* {@inheritdoc}
*/
public function write($name, array $data) {
return $this->getStorage()
->write($name, $data);
}
/**
* {@inheritdoc}
*/
public function delete($name) {
return $this->getStorage()
->delete($name);
}
/**
* {@inheritdoc}
*/
public function rename($name, $new_name) {
return $this->getStorage()
->rename($name, $new_name);
}
/**
* {@inheritdoc}
*/
public function encode($data) {
return $this->getStorage()
->encode($data);
}
/**
* {@inheritdoc}
*/
public function decode($raw) {
return $this->getStorage()
->decode($raw);
}
/**
* {@inheritdoc}
*/
public function listAll($prefix = '') {
return $this->getStorage()
->listAll($prefix);
}
/**
* {@inheritdoc}
*/
public function deleteAll($prefix = '') {
return $this->getStorage()
->deleteAll($prefix);
}
/**
* {@inheritdoc}
*/
public function createCollection($collection) {
// We return the collection directly.
// This means that the collection will not be an instance of ManagedStorage
// But this doesn't matter because the storage is retrieved from the
// manager only the first time it is accessed.
return $this->getStorage()
->createCollection($collection);
}
/**
* {@inheritdoc}
*/
public function getAllCollectionNames() {
return $this->getStorage()
->getAllCollectionNames();
}
/**
* {@inheritdoc}
*/
public function getCollectionName() {
return $this->getStorage()
->getCollectionName();
}
/**
* Get the decorated storage from the manager if necessary.
*
* @return \Drupal\Core\Config\StorageInterface
* The config storage.
*/
protected function getStorage() {
// Get the storage from the manager the first time it is needed.
if (!isset($this->storage)) {
$this->storage = $this->manager
->getStorage();
}
return $this->storage;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ManagedStorage::$manager | protected | property | The storage manager to get the storage to decorate. | |
ManagedStorage::$storage | protected | property | The decorated storage. | |
ManagedStorage::createCollection | public | function | Creates a collection on the storage. | Overrides StorageInterface::createCollection |
ManagedStorage::decode | public | function | Decodes configuration data from the storage-specific format. | Overrides StorageInterface::decode |
ManagedStorage::delete | public | function | Deletes a configuration object from the storage. | Overrides StorageInterface::delete |
ManagedStorage::deleteAll | public | function | Deletes configuration objects whose names start with a given prefix. | Overrides StorageInterface::deleteAll |
ManagedStorage::encode | public | function | Encodes configuration data into the storage-specific format. | Overrides StorageInterface::encode |
ManagedStorage::exists | public | function | Returns whether a configuration object exists. | Overrides StorageInterface::exists |
ManagedStorage::getAllCollectionNames | public | function | Gets the existing collections. | Overrides StorageInterface::getAllCollectionNames |
ManagedStorage::getCollectionName | public | function | Gets the name of the current collection the storage is using. | Overrides StorageInterface::getCollectionName |
ManagedStorage::getStorage | protected | function | Get the decorated storage from the manager if necessary. | |
ManagedStorage::listAll | public | function | Gets configuration object names starting with a given prefix. | Overrides StorageInterface::listAll |
ManagedStorage::read | public | function | Reads configuration data from the storage. | Overrides StorageInterface::read |
ManagedStorage::readMultiple | public | function | Reads configuration data from the storage. | Overrides StorageInterface::readMultiple |
ManagedStorage::rename | public | function | Renames a configuration object in the storage. | Overrides StorageInterface::rename |
ManagedStorage::write | public | function | Writes configuration data to the storage. | Overrides StorageInterface::write |
ManagedStorage::__construct | public | function | ManagedStorage constructor. | |
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.