class AutoloadingStorage
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Config/AutoloadingStorage.php \Drupal\Core\Config\AutoloadingStorage
Defines the autoloading storage.
Allows configuration to be read that contains constants and enum from extensions that are not yet installed. To do so, a class loader is temporarily registered while reading from configuration.
Hierarchy
- class \Drupal\Core\Config\AutoloadingStorage implements \Drupal\Core\Config\StorageInterface, \Drupal\Core\Config\StorageCacheInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait
Expanded class hierarchy of AutoloadingStorage
1 string reference to 'AutoloadingStorage'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses AutoloadingStorage
File
-
core/
lib/ Drupal/ Core/ Config/ AutoloadingStorage.php, line 17
Namespace
Drupal\Core\ConfigView source
class AutoloadingStorage implements StorageInterface, StorageCacheInterface {
use DependencySerializationTrait;
/**
* Class loader that loads code from extensions provided to the constructor.
*/
protected ?ClassLoader $classloader = NULL;
/**
* Constructs a new AutoloadingStorage.
*
* @param \Drupal\Core\Config\StorageInterface $storage
* A configuration storage to be wrapped.
* @param string[] $newExtensions
* A list of new extensions in the source storage that we need to allow to
* autoload while reading. The values should be absolute paths to the
* extension directory.
*/
public function __construct(protected StorageInterface $storage, array $newExtensions = []) {
if (!empty($newExtensions)) {
$this->classloader = new ClassLoader();
foreach ($newExtensions as $extension => $dir) {
$this->classloader
->addPsr4("Drupal\\{$extension}\\", $dir . '/src');
}
}
}
/**
* {@inheritdoc}
*/
public function exists($name) : bool {
return $this->storage
->exists($name);
}
/**
* {@inheritdoc}
*/
public function read($name) : array|false {
$this->classloader?->register(TRUE);
try {
$data = $this->storage
->read($name);
} finally {
$this->classloader?->unregister();
}
return $data;
}
/**
* {@inheritdoc}
*/
public function readMultiple(array $names) : array {
$this->classloader?->register(TRUE);
try {
$data = $this->storage
->readMultiple($names);
} finally {
$this->classloader?->unregister();
}
return $data;
}
/**
* {@inheritdoc}
*/
public function write($name, array $data) : bool {
return $this->storage
->write($name, $data);
}
/**
* {@inheritdoc}
*/
public function delete($name) : bool {
return $this->storage
->delete($name);
}
/**
* {@inheritdoc}
*/
public function rename($name, $new_name) : bool {
return $this->storage
->rename($name, $new_name);
}
/**
* {@inheritdoc}
*/
public function encode($data) : string {
return $this->storage
->encode($data);
}
/**
* {@inheritdoc}
*/
public function decode($raw) : array {
return $this->storage
->decode($raw);
}
/**
* {@inheritdoc}
*/
public function listAll($prefix = '') : array {
return $this->storage
->listAll($prefix);
}
/**
* {@inheritdoc}
*/
public function deleteAll($prefix = '') : bool {
return $this->storage
->deleteAll($prefix);
}
/**
* Clears the static list cache.
*/
public function resetListCache() : void {
if ($this->storage instanceof StorageCacheInterface) {
$this->storage
->resetListCache();
}
}
/**
* {@inheritdoc}
*/
public function createCollection($collection) : static {
$storage = new static($this->storage
->createCollection($collection));
$storage->classloader = $this->classloader;
return $storage;
}
/**
* {@inheritdoc}
*/
public function getAllCollectionNames() : array {
return $this->storage
->getAllCollectionNames();
}
/**
* {@inheritdoc}
*/
public function getCollectionName() : string {
return $this->storage
->getCollectionName();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.