vendor/symfony/config/Definition/Processor.php line 50

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Config\Definition;
  11. /**
  12.  * This class is the entry point for config normalization/merging/finalization.
  13.  *
  14.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  15.  *
  16.  * @final since version 4.1
  17.  */
  18. class Processor
  19. {
  20.     /**
  21.      * Processes an array of configurations.
  22.      *
  23.      * @param array $configs An array of configuration items to process
  24.      *
  25.      * @return array The processed configuration
  26.      */
  27.     public function process(NodeInterface $configTree, array $configs)
  28.     {
  29.         $currentConfig = [];
  30.         foreach ($configs as $config) {
  31.             $config $configTree->normalize($config);
  32.             $currentConfig $configTree->merge($currentConfig$config);
  33.         }
  34.         return $configTree->finalize($currentConfig);
  35.     }
  36.     /**
  37.      * Processes an array of configurations.
  38.      *
  39.      * @param array $configs An array of configuration items to process
  40.      *
  41.      * @return array The processed configuration
  42.      */
  43.     public function processConfiguration(ConfigurationInterface $configuration, array $configs)
  44.     {
  45.         return $this->process($configuration->getConfigTreeBuilder()->buildTree(), $configs);
  46.     }
  47.     /**
  48.      * Normalizes a configuration entry.
  49.      *
  50.      * This method returns a normalize configuration array for a given key
  51.      * to remove the differences due to the original format (YAML and XML mainly).
  52.      *
  53.      * Here is an example.
  54.      *
  55.      * The configuration in XML:
  56.      *
  57.      * <twig:extension>twig.extension.foo</twig:extension>
  58.      * <twig:extension>twig.extension.bar</twig:extension>
  59.      *
  60.      * And the same configuration in YAML:
  61.      *
  62.      * extensions: ['twig.extension.foo', 'twig.extension.bar']
  63.      *
  64.      * @param array  $config A config array
  65.      * @param string $key    The key to normalize
  66.      * @param string $plural The plural form of the key if it is irregular
  67.      *
  68.      * @return array
  69.      */
  70.     public static function normalizeConfig($config$key$plural null)
  71.     {
  72.         if (null === $plural) {
  73.             $plural $key.'s';
  74.         }
  75.         if (isset($config[$plural])) {
  76.             return $config[$plural];
  77.         }
  78.         if (isset($config[$key])) {
  79.             if (\is_string($config[$key]) || !\is_int(key($config[$key]))) {
  80.                 // only one
  81.                 return [$config[$key]];
  82.             }
  83.             return $config[$key];
  84.         }
  85.         return [];
  86.     }
  87. }