[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
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 = []; 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 = static::class; 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 = static::class; 83 84 if (false !== strpos($class, "\0")) { 85 return null; // ignore anonymous classes 86 } 87 88 $class = substr_replace($class, '\Configuration', strrpos($class, '\\')); 89 $class = $container->getReflectionClass($class); 90 $constructor = $class ? $class->getConstructor() : null; 91 92 return $class && (!$constructor || !$constructor->getNumberOfRequiredParameters()) ? $class->newInstance() : null; 93 } 94 95 /** 96 * @return array 97 */ 98 final protected function processConfiguration(ConfigurationInterface $configuration, array $configs) 99 { 100 $processor = new Processor(); 101 102 return $this->processedConfigs[] = $processor->processConfiguration($configuration, $configs); 103 } 104 105 /** 106 * @internal 107 */ 108 final public function getProcessedConfigs() 109 { 110 try { 111 return $this->processedConfigs; 112 } finally { 113 $this->processedConfigs = []; 114 } 115 } 116 117 /** 118 * @return bool Whether the configuration is enabled 119 * 120 * @throws InvalidArgumentException When the config is not enableable 121 */ 122 protected function isConfigEnabled(ContainerBuilder $container, array $config) 123 { 124 if (!\array_key_exists('enabled', $config)) { 125 throw new InvalidArgumentException("The config array has no 'enabled' key."); 126 } 127 128 return (bool) $container->getParameterBag()->resolveValue($config['enabled']); 129 } 130 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |