NormalizedReadOnlyStorage.php in Configuration Normalizer 8
File
src/Config/NormalizedReadOnlyStorage.php
View source
<?php
namespace Drupal\config_normalizer\Config;
use Drupal\config_filter\Config\ReadOnlyStorage;
use Drupal\config_normalizer\ConfigItemNormalizer;
use Drupal\config_normalizer\Plugin\ConfigNormalizerManager;
use Drupal\Core\Config\StorageInterface;
class NormalizedReadOnlyStorage extends ReadOnlyStorage implements NormalizedReadOnlyStorageInterface {
protected $normalizerManager;
protected $configItemNormalizer;
protected $context;
public function __construct(StorageInterface $storage, ConfigNormalizerManager $normalizer_manager, array $context = []) {
parent::__construct($storage);
$this->normalizerManager = $normalizer_manager;
$this->configItemNormalizer = new ConfigItemNormalizer($normalizer_manager, $context);
$this
->setContext($context);
}
public function getContext() {
return $this->context;
}
public function setContext(array $context = []) {
$context += NormalizedReadOnlyStorageInterface::DEFAULT_CONTEXT;
$this->context = $context;
}
public function read($name) {
$data = parent::read($name);
$data = $this
->normalize($name, $data);
return $data;
}
public function readMultiple(array $names) {
$list = parent::readMultiple($names);
foreach ($list as $name => &$data) {
$data = $this
->normalize($name, $data);
}
return $list;
}
public function createCollection($collection) {
return new static($this->storage
->createCollection($collection), $this->normalizerManager, $this->context);
}
protected function normalize($name, $data) {
if (!is_bool($data)) {
$data = $this->configItemNormalizer
->normalize($name, $data, $this->context);
}
return $data;
}
}