[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Extension/ -> Extension.php (source)

   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\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;
  21  
  22  /**
  23   * Provides useful features shared by many extensions.
  24   *
  25   * @author Fabien Potencier <fabien@symfony.com>
  26   */
  27  abstract class Extension implements ExtensionInterface, ConfigurationExtensionInterface
  28  {
  29      /**
  30       * {@inheritdoc}
  31       */
  32      public function getXsdValidationBasePath()
  33      {
  34          return false;
  35      }
  36  
  37      /**
  38       * {@inheritdoc}
  39       */
  40      public function getNamespace()
  41      {
  42          return 'http://example.org/schema/dic/'.$this->getAlias();
  43      }
  44  
  45      /**
  46       * Returns the recommended alias to use in XML.
  47       *
  48       * This alias is also the mandatory prefix to use when using YAML.
  49       *
  50       * This convention is to remove the "Extension" postfix from the class
  51       * name and then lowercase and underscore the result. So:
  52       *
  53       *     AcmeHelloExtension
  54       *
  55       * becomes
  56       *
  57       *     acme_hello
  58       *
  59       * This can be overridden in a sub-class to specify the alias manually.
  60       *
  61       * @return string The alias
  62       *
  63       * @throws BadMethodCallException When the extension name does not follow conventions
  64       */
  65      public function getAlias()
  66      {
  67          $className = get_class($this);
  68          if (substr($className, -9) != 'Extension') {
  69              throw new BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.');
  70          }
  71          $classBaseName = substr(strrchr($className, '\\'), 1, -9);
  72  
  73          return Container::underscore($classBaseName);
  74      }
  75  
  76      /**
  77       * {@inheritdoc}
  78       */
  79      public function getConfiguration(array $config, ContainerBuilder $container)
  80      {
  81          $reflected = new \ReflectionClass($this);
  82          $namespace = $reflected->getNamespaceName();
  83  
  84          $class = $namespace.'\\Configuration';
  85          if (class_exists($class)) {
  86              $r = new \ReflectionClass($class);
  87              $container->addResource(new FileResource($r->getFileName()));
  88  
  89              if (!method_exists($class, '__construct')) {
  90                  return new $class();
  91              }
  92          }
  93      }
  94  
  95      final protected function processConfiguration(ConfigurationInterface $configuration, array $configs)
  96      {
  97          $processor = new Processor();
  98  
  99          return $processor->processConfiguration($configuration, $configs);
 100      }
 101  
 102      /**
 103       * @param ContainerBuilder $container
 104       * @param array            $config
 105       *
 106       * @return bool Whether the configuration is enabled
 107       *
 108       * @throws InvalidArgumentException When the config is not enableable
 109       */
 110      protected function isConfigEnabled(ContainerBuilder $container, array $config)
 111      {
 112          if (!array_key_exists('enabled', $config)) {
 113              throw new InvalidArgumentException("The config array has no 'enabled' key.");
 114          }
 115  
 116          return (bool) $container->getParameterBag()->resolveValue($config['enabled']);
 117      }
 118  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1