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