class ConfigReadonlyStorage in Configuration Read-only mode 8
Same name and namespace in other branches
- 7 lib/Drupal/config_readonly/Config/ConfigReadonlyStorage.php \Drupal\config_readonly\Config\ConfigReadonlyStorage
Defines a config read-only storage controller.
This fails on write operations.
Hierarchy
- class \Drupal\Core\Config\CachedStorage implements StorageCacheInterface, StorageInterface uses DependencySerializationTrait
- class \Drupal\config_readonly\Config\ConfigReadonlyStorage uses ConfigReadonlyWhitelistTrait
Expanded class hierarchy of ConfigReadonlyStorage
File
- src/
Config/ ConfigReadonlyStorage.php, line 23
Namespace
Drupal\config_readonly\ConfigView source
class ConfigReadonlyStorage extends CachedStorage {
use ConfigReadonlyWhitelistTrait;
/**
* The used lock backend instance.
*
* @var \Drupal\Core\Lock\LockBackendInterface
*/
protected $lock;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* Constructs a new ConfigReadonlyStorage.
*
* @param \Drupal\Core\Config\StorageInterface $storage
* A configuration storage to be cached.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* A cache backend used to store configuration.
* @param \Drupal\Core\Lock\LockBackendInterface $lock
* The lock backend to check if config imports are in progress.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke hooks.
*/
public function __construct(StorageInterface $storage, CacheBackendInterface $cache, LockBackendInterface $lock, RequestStack $request_stack, ModuleHandlerInterface $module_handler) {
parent::__construct($storage, $cache);
$this->lock = $lock;
$this->requestStack = $request_stack;
$this
->setModuleHandler($module_handler);
}
/**
* {@inheritdoc}
*/
public function createCollection($collection) {
return new static($this->storage
->createCollection($collection), $this->cache, $this->lock, $this->requestStack, $this->moduleHandler);
}
/**
* {@inheritdoc}
*
* @throws \Drupal\config_readonly\Exception\ConfigReadonlyStorageException
*/
public function write($name, array $data) {
$this
->checkLock($name);
return parent::write($name, $data);
}
/**
* {@inheritdoc}
*
* @throws \Drupal\config_readonly\Exception\ConfigReadonlyStorageException
*/
public function delete($name) {
$this
->checkLock($name);
return parent::delete($name);
}
/**
* {@inheritdoc}
*
* @throws \Drupal\config_readonly\Exception\ConfigReadonlyStorageException
*/
public function rename($name, $new_name) {
$this
->checkLock($name);
$this
->checkLock($new_name);
return parent::rename($name, $new_name);
}
/**
* {@inheritdoc}
*
* @throws \Drupal\config_readonly\Exception\ConfigReadonlyStorageException
*/
public function deleteAll($prefix = '') {
$this
->checkLock();
return parent::deleteAll($prefix);
}
/**
* Check whether config is currently locked.
*
* @param string $name
* Check for a specific lock config.
*
* @throws \Drupal\config_readonly\Exception\ConfigReadonlyStorageException
*/
protected function checkLock($name = '') {
// If settings.php says to lock config changes and if the config importer
// isn't running (we do not want to lock config imports), then throw an
// exception.
// @see \Drupal\Core\Config\ConfigImporter::alreadyImporting()
if (Settings::get('config_readonly') && $this->lock
->lockMayBeAvailable(ConfigImporter::LOCK_NAME)) {
$request = $this->requestStack
->getCurrentRequest();
if ($request && $request->attributes
->get(RouteObjectInterface::ROUTE_NAME) === 'system.db_update') {
// We seem to be in the middle of running update.php.
// @see \Drupal\Core\Update\UpdateKernel::setupRequestMatch()
// @todo - always allow or support a flag for blocking it?
return;
}
// Don't block particular patterns.
if ($name && $this
->matchesWhitelistPattern($name)) {
return;
}
throw new ConfigReadonlyStorageException('Your site configuration active store is currently locked.');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CachedStorage:: |
protected | property | The instantiated Cache backend. | |
CachedStorage:: |
protected | property | List of listAll() prefixes with their results. | |
CachedStorage:: |
protected | property | The configuration storage to be cached. | |
CachedStorage:: |
public | function |
Decodes configuration data from the storage-specific format. Overrides StorageInterface:: |
|
CachedStorage:: |
public | function |
Encodes configuration data into the storage-specific format. Overrides StorageInterface:: |
|
CachedStorage:: |
public | function |
Returns whether a configuration object exists. Overrides StorageInterface:: |
|
CachedStorage:: |
protected | function | Finds configuration object names starting with a given prefix. | |
CachedStorage:: |
public | function |
Gets the existing collections. Overrides StorageInterface:: |
|
CachedStorage:: |
protected | function | Returns a cache key for a configuration name using the collection. | |
CachedStorage:: |
protected | function | Returns a cache key map for an array of configuration names. | |
CachedStorage:: |
public | function |
Gets the name of the current collection the storage is using. Overrides StorageInterface:: |
|
CachedStorage:: |
protected | function | Returns a cache ID prefix to use for the collection. | |
CachedStorage:: |
public | function |
Gets configuration object names starting with a given prefix. Overrides StorageInterface:: |
|
CachedStorage:: |
public | function |
Reads configuration data from the storage. Overrides StorageInterface:: |
|
CachedStorage:: |
public | function |
Reads configuration data from the storage. Overrides StorageInterface:: |
|
CachedStorage:: |
public | function |
Clears the static list cache. Overrides StorageCacheInterface:: |
|
ConfigReadonlyStorage:: |
protected | property | The used lock backend instance. | |
ConfigReadonlyStorage:: |
protected | property | The request stack. | |
ConfigReadonlyStorage:: |
protected | function | Check whether config is currently locked. | |
ConfigReadonlyStorage:: |
public | function |
Creates a collection on the storage. Overrides CachedStorage:: |
|
ConfigReadonlyStorage:: |
public | function |
Overrides CachedStorage:: |
|
ConfigReadonlyStorage:: |
public | function |
Overrides CachedStorage:: |
|
ConfigReadonlyStorage:: |
public | function |
Overrides CachedStorage:: |
|
ConfigReadonlyStorage:: |
public | function |
Overrides CachedStorage:: |
|
ConfigReadonlyStorage:: |
public | function |
Constructs a new ConfigReadonlyStorage. Overrides CachedStorage:: |
|
ConfigReadonlyWhitelistTrait:: |
protected | property | The module handler. | |
ConfigReadonlyWhitelistTrait:: |
protected | property | An array to store the whitelist ignore patterns. | |
ConfigReadonlyWhitelistTrait:: |
protected | function | Get whitelist patterns. | |
ConfigReadonlyWhitelistTrait:: |
protected | function | Check if the given name matches any whitelist pattern. | |
ConfigReadonlyWhitelistTrait:: |
protected | function | Set the module handler. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
StorageInterface:: |
constant | The default collection name. |