composer package updates
[openemr.git] / vendor / symfony / dependency-injection / Extension / Extension.php
blob224d18a44d67160311fb5d26777cf91eb2573458
1 <?php
3 /*
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\DependencyInjection\Extension;
14 use Symfony\Component\DependencyInjection\Container;
15 use Symfony\Component\DependencyInjection\Exception\BadMethodCallException;
16 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
17 use Symfony\Component\Config\Resource\FileResource;
18 use Symfony\Component\DependencyInjection\ContainerBuilder;
19 use Symfony\Component\Config\Definition\Processor;
20 use Symfony\Component\Config\Definition\ConfigurationInterface;
22 /**
23 * Provides useful features shared by many extensions.
25 * @author Fabien Potencier <fabien@symfony.com>
27 abstract class Extension implements ExtensionInterface, ConfigurationExtensionInterface
29 /**
30 * {@inheritdoc}
32 public function getXsdValidationBasePath()
34 return false;
37 /**
38 * {@inheritdoc}
40 public function getNamespace()
42 return 'http://example.org/schema/dic/'.$this->getAlias();
45 /**
46 * Returns the recommended alias to use in XML.
48 * This alias is also the mandatory prefix to use when using YAML.
50 * This convention is to remove the "Extension" postfix from the class
51 * name and then lowercase and underscore the result. So:
53 * AcmeHelloExtension
55 * becomes
57 * acme_hello
59 * This can be overridden in a sub-class to specify the alias manually.
61 * @return string The alias
63 * @throws BadMethodCallException When the extension name does not follow conventions
65 public function getAlias()
67 $className = get_class($this);
68 if ('Extension' != substr($className, -9)) {
69 throw new BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.');
71 $classBaseName = substr(strrchr($className, '\\'), 1, -9);
73 return Container::underscore($classBaseName);
76 /**
77 * {@inheritdoc}
79 public function getConfiguration(array $config, ContainerBuilder $container)
81 $reflected = new \ReflectionClass($this);
82 $namespace = $reflected->getNamespaceName();
84 $class = $namespace.'\\Configuration';
85 if (class_exists($class)) {
86 $r = new \ReflectionClass($class);
87 $container->addResource(new FileResource($r->getFileName()));
89 if (!method_exists($class, '__construct')) {
90 return new $class();
95 final protected function processConfiguration(ConfigurationInterface $configuration, array $configs)
97 $processor = new Processor();
99 return $processor->processConfiguration($configuration, $configs);
103 * @return bool Whether the configuration is enabled
105 * @throws InvalidArgumentException When the config is not enableable
107 protected function isConfigEnabled(ContainerBuilder $container, array $config)
109 if (!array_key_exists('enabled', $config)) {
110 throw new InvalidArgumentException("The config array has no 'enabled' key.");
113 return (bool) $container->getParameterBag()->resolveValue($config['enabled']);