You are here

class ConfigItemNormalizer in Configuration Normalizer 8

Same name and namespace in other branches
  1. 2.0.x src/ConfigItemNormalizer.php \Drupal\config_normalizer\ConfigItemNormalizer

Class responsible for performing configuration normalization.

Hierarchy

Expanded class hierarchy of ConfigItemNormalizer

2 files declare their use of ConfigItemNormalizer
NormalizedReadOnlyStorage.php in src/Config/NormalizedReadOnlyStorage.php
NormalizedReadOnlyStorageInterface.php in src/Config/NormalizedReadOnlyStorageInterface.php

File

src/ConfigItemNormalizer.php, line 10

Namespace

Drupal\config_normalizer
View source
class ConfigItemNormalizer implements ConfigItemNormalizerInterface {

  /**
   * The configuration normalizer plugin manager.
   *
   * @var \Drupal\Component\Plugin\PluginManagerInterface
   */
  protected $normalizerManager;

  /**
   * Local cache for normalizer instances.
   *
   * @var array
   */
  protected $normalizers;

  /**
   * Constructs a new ConfigItemNormalizer object.
   *
   * @param \Drupal\Component\Plugin\PluginManagerInterface $normalizer_manager
   *   The configuration normalizer plugin manager.
   */
  public function __construct(PluginManagerInterface $normalizer_manager) {
    $this->normalizerManager = $normalizer_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function normalize($name, array $data, array $context = []) {
    $normalizers = $this->normalizerManager
      ->getDefinitions();
    uasort($normalizers, [
      'Drupal\\Component\\Utility\\SortArray',
      'sortByWeightElement',
    ]);
    foreach (array_keys($normalizers) as $id) {
      $this
        ->applyNormalizer($id, $name, $data, $context);
    }
    return $data;
  }

  /**
   * {@inheritdoc}
   */
  protected function applyNormalizer($id, $name, array &$data, array $context) {
    $normalizer = $this
      ->getNormalizerInstance($id);
    $normalizer
      ->normalize($name, $data, $context);
  }

  /**
   * Returns an instance of the specified package generation normalizer.
   *
   * @param string $id
   *   The string identifier of the normalizer to use to package
   *   configuration.
   *
   * @return \Drupal\config_normalizer\Plugin\ConfigNormalizerInterface
   */
  protected function getNormalizerInstance($id) {
    if (!isset($this->normalizers[$id])) {
      $instance = $this->normalizerManager
        ->createInstance($id);
      $this->normalizers[$id] = $instance;
    }
    return $this->normalizers[$id];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigItemNormalizer::$normalizerManager protected property The configuration normalizer plugin manager.
ConfigItemNormalizer::$normalizers protected property Local cache for normalizer instances.
ConfigItemNormalizer::applyNormalizer protected function
ConfigItemNormalizer::getNormalizerInstance protected function Returns an instance of the specified package generation normalizer.
ConfigItemNormalizer::normalize public function Normalizes config for comparison. Overrides ConfigItemNormalizerInterface::normalize
ConfigItemNormalizer::__construct public function Constructs a new ConfigItemNormalizer object.