class ReversibleConfigDiffer in Update helper 8
Same name and namespace in other branches
- 2.x src/ReversibleConfigDiffer.php \Drupal\update_helper\ReversibleConfigDiffer
Overwrite of config updater differ.
Normalization is changed so that it can be 2-way normalization, not 1-way. Also format is adjusted to better supports converting from/to config array.
TODO:
- (de)normalization should be solved properly. It does not support option with multiple assoc arrays in array. In Yaml empty line with '-' and then parameters after it.
@package Drupal\update_helper
Hierarchy
- class \Drupal\config_update\ConfigDiffer implements ConfigDiffInterface uses StringTranslationTrait
- class \Drupal\update_helper\ReversibleConfigDiffer
Expanded class hierarchy of ReversibleConfigDiffer
1 string reference to 'ReversibleConfigDiffer'
1 service uses ReversibleConfigDiffer
File
- src/
ReversibleConfigDiffer.php, line 21
Namespace
Drupal\update_helperView source
class ReversibleConfigDiffer extends ConfigDiffer {
/**
* Config diff transformer service.
*
* @var \Drupal\update_helper\ConfigDiffTransformer
*/
protected $configDiffTransformer;
/**
* ConfigDiffer constructor.
*
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* String translation service.
* @param \Drupal\update_helper\ConfigDiffTransformer $config_diff_transformer
* Configuration transformer for diffing.
* @param string[] $ignore
* Config components to ignore.
* @param string $hierarchy_prefix
* Prefix to use in diffs for array hierarchy.
* @param string $value_prefix
* Prefix to use in diffs for array value.
*/
public function __construct(TranslationInterface $translation, ConfigDiffTransformer $config_diff_transformer, array $ignore = [
'uuid',
'_core',
], $hierarchy_prefix = '::', $value_prefix = ' : ') {
parent::__construct($translation, $ignore, $hierarchy_prefix, $value_prefix);
$this->configDiffTransformer = $config_diff_transformer;
}
/**
* Strip some generic fields (uuid, _core).
*
* @param mixed $data
* Configuration array.
*
* @return mixed
* Returns stripped configuration.
*/
public function stripIgnore($data) {
foreach ($this->ignore as $element) {
unset($data[$element]);
}
return $data;
}
/**
* {@inheritdoc}
*/
protected function normalize($config) {
// Recursively normalize remaining elements, if they are arrays.
foreach ($config as $key => $value) {
if (is_array($value)) {
$config[$key] = $this
->normalize($value);
}
}
// Sort and return.
ksort($config);
return $config;
}
/**
* {@inheritdoc}
*/
protected function format(array $config, $prefix = '') {
return $this->configDiffTransformer
->transform($config, $prefix);
}
/**
* {@inheritdoc}
*/
public function same($source, $target) {
$source = $this
->stripIgnore($source);
$target = $this
->stripIgnore($target);
return parent::same($source, $target);
}
/**
* {@inheritdoc}
*/
public function diff($source, $target) {
$source = $this
->stripIgnore($source);
$target = $this
->stripIgnore($target);
return parent::diff($source, $target);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigDiffer:: |
protected | property | Prefix to use to indicate config hierarchy. | |
ConfigDiffer:: |
protected | property | List of elements to ignore on top level when comparing config. | |
ConfigDiffer:: |
protected | property | Prefix to use to indicate config values. | |
ConfigDiffer:: |
protected | function | Recursively sorts an array by key, and removes empty arrays. | |
ReversibleConfigDiffer:: |
protected | property | Config diff transformer service. | |
ReversibleConfigDiffer:: |
public | function |
Calculates differences between config. Overrides ConfigDiffer:: |
|
ReversibleConfigDiffer:: |
protected | function |
Formats config for showing differences. Overrides ConfigDiffer:: |
|
ReversibleConfigDiffer:: |
protected | function |
Normalizes config for comparison. Overrides ConfigDiffer:: |
|
ReversibleConfigDiffer:: |
public | function |
Decides if two configuration arrays are considered to be the same. Overrides ConfigDiffer:: |
|
ReversibleConfigDiffer:: |
public | function | Strip some generic fields (uuid, _core). | |
ReversibleConfigDiffer:: |
public | function |
ConfigDiffer constructor. Overrides ConfigDiffer:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |