Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / symfony / dependency-injection / Extension / Extension.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\DependencyInjection\Extension;
13
14 use Symfony\Component\Config\Definition\ConfigurationInterface;
15 use Symfony\Component\Config\Definition\Processor;
16 use Symfony\Component\DependencyInjection\Container;
17 use Symfony\Component\DependencyInjection\ContainerBuilder;
18 use Symfony\Component\DependencyInjection\Exception\BadMethodCallException;
19 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
20
21 /**
22  * Provides useful features shared by many extensions.
23  *
24  * @author Fabien Potencier <fabien@symfony.com>
25  */
26 abstract class Extension implements ExtensionInterface, ConfigurationExtensionInterface
27 {
28     private $processedConfigs = array();
29
30     /**
31      * {@inheritdoc}
32      */
33     public function getXsdValidationBasePath()
34     {
35         return false;
36     }
37
38     /**
39      * {@inheritdoc}
40      */
41     public function getNamespace()
42     {
43         return 'http://example.org/schema/dic/'.$this->getAlias();
44     }
45
46     /**
47      * Returns the recommended alias to use in XML.
48      *
49      * This alias is also the mandatory prefix to use when using YAML.
50      *
51      * This convention is to remove the "Extension" postfix from the class
52      * name and then lowercase and underscore the result. So:
53      *
54      *     AcmeHelloExtension
55      *
56      * becomes
57      *
58      *     acme_hello
59      *
60      * This can be overridden in a sub-class to specify the alias manually.
61      *
62      * @return string The alias
63      *
64      * @throws BadMethodCallException When the extension name does not follow conventions
65      */
66     public function getAlias()
67     {
68         $className = \get_class($this);
69         if ('Extension' != substr($className, -9)) {
70             throw new BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.');
71         }
72         $classBaseName = substr(strrchr($className, '\\'), 1, -9);
73
74         return Container::underscore($classBaseName);
75     }
76
77     /**
78      * {@inheritdoc}
79      */
80     public function getConfiguration(array $config, ContainerBuilder $container)
81     {
82         $class = \get_class($this);
83         $class = substr_replace($class, '\Configuration', strrpos($class, '\\'));
84         $class = $container->getReflectionClass($class);
85         $constructor = $class ? $class->getConstructor() : null;
86
87         if ($class && (!$constructor || !$constructor->getNumberOfRequiredParameters())) {
88             return $class->newInstance();
89         }
90     }
91
92     final protected function processConfiguration(ConfigurationInterface $configuration, array $configs)
93     {
94         $processor = new Processor();
95
96         return $this->processedConfigs[] = $processor->processConfiguration($configuration, $configs);
97     }
98
99     /**
100      * @internal
101      */
102     final public function getProcessedConfigs()
103     {
104         try {
105             return $this->processedConfigs;
106         } finally {
107             $this->processedConfigs = array();
108         }
109     }
110
111     /**
112      * @return bool Whether the configuration is enabled
113      *
114      * @throws InvalidArgumentException When the config is not enableable
115      */
116     protected function isConfigEnabled(ContainerBuilder $container, array $config)
117     {
118         if (!array_key_exists('enabled', $config)) {
119             throw new InvalidArgumentException("The config array has no 'enabled' key.");
120         }
121
122         return (bool) $container->getParameterBag()->resolveValue($config['enabled']);
123     }
124 }