4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Config\Definition;
15 * This class is the entry point for config normalization/merging/finalization.
17 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
22 * Processes an array of configurations.
24 * @param NodeInterface $configTree The node tree describing the configuration
25 * @param array $configs An array of configuration items to process
27 * @return array The processed configuration
29 public function process(NodeInterface $configTree, array $configs)
31 $currentConfig = array();
32 foreach ($configs as $config) {
33 $config = $configTree->normalize($config);
34 $currentConfig = $configTree->merge($currentConfig, $config);
37 return $configTree->finalize($currentConfig);
41 * Processes an array of configurations.
43 * @param ConfigurationInterface $configuration The configuration class
44 * @param array $configs An array of configuration items to process
46 * @return array The processed configuration
48 public function processConfiguration(ConfigurationInterface $configuration, array $configs)
50 return $this->process($configuration->getConfigTreeBuilder()->buildTree(), $configs);
54 * Normalizes a configuration entry.
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).
61 * The configuration in XML:
63 * <twig:extension>twig.extension.foo</twig:extension>
64 * <twig:extension>twig.extension.bar</twig:extension>
66 * And the same configuration in YAML:
68 * extensions: ['twig.extension.foo', 'twig.extension.bar']
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
76 public static function normalizeConfig($config, $key, $plural = null)
78 if (null === $plural) {
82 if (isset($config[$plural])) {
83 return $config[$plural];
86 if (isset($config[$key])) {
87 if (is_string($config[$key]) || !is_int(key($config[$key]))) {
89 return array($config[$key]);