/vendor/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php

https://github.com/israelnoguera/parejas · PHP · 125 lines · 55 code · 16 blank · 54 comment · 4 complexity · 208520f1830f5856479725427c74ca1b MD5 · raw file

  1. <?php
  2. namespace Symfony\Component\HttpKernel\DependencyInjection;
  3. use Symfony\Component\Config\Definition\Processor;
  4. use Symfony\Component\Config\Definition\ConfigurationInterface;
  5. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  6. use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
  7. use Symfony\Component\DependencyInjection\ContainerBuilder;
  8. use Symfony\Component\DependencyInjection\Container;
  9. /*
  10. * This file is part of the Symfony framework.
  11. *
  12. * (c) Fabien Potencier <fabien@symfony.com>
  13. *
  14. * This source file is subject to the MIT license that is bundled
  15. * with this source code in the file LICENSE.
  16. */
  17. /**
  18. * Provides useful features shared by many extensions.
  19. *
  20. * @author Fabien Potencier <fabien@symfony.com>
  21. */
  22. abstract class Extension implements ExtensionInterface, ConfigurationExtensionInterface
  23. {
  24. private $classes = array();
  25. /**
  26. * Gets the classes to cache.
  27. *
  28. * @return array An array of classes
  29. */
  30. public function getClassesToCompile()
  31. {
  32. return $this->classes;
  33. }
  34. /**
  35. * Adds classes to the class cache.
  36. *
  37. * @param array $classes An array of classes
  38. */
  39. public function addClassesToCompile(array $classes)
  40. {
  41. $this->classes = array_merge($this->classes, $classes);
  42. }
  43. /**
  44. * Returns the base path for the XSD files.
  45. *
  46. * @return string The XSD base path
  47. */
  48. public function getXsdValidationBasePath()
  49. {
  50. return false;
  51. }
  52. /**
  53. * Returns the namespace to be used for this extension (XML namespace).
  54. *
  55. * @return string The XML namespace
  56. */
  57. public function getNamespace()
  58. {
  59. return 'http://example.org/schema/dic/'.$this->getAlias();
  60. }
  61. /**
  62. * Returns the recommended alias to use in XML.
  63. *
  64. * This alias is also the mandatory prefix to use when using YAML.
  65. *
  66. * This convention is to remove the "Extension" postfix from the class
  67. * name and then lowercase and underscore the result. So:
  68. *
  69. * AcmeHelloExtension
  70. *
  71. * becomes
  72. *
  73. * acme_hello
  74. *
  75. * This can be overridden in a sub-class to specify the alias manually.
  76. *
  77. * @return string The alias
  78. */
  79. public function getAlias()
  80. {
  81. $className = get_class($this);
  82. if (substr($className, -9) != 'Extension') {
  83. throw new \BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.');
  84. }
  85. $classBaseName = substr(strrchr($className, '\\'), 1, -9);
  86. return Container::underscore($classBaseName);
  87. }
  88. protected final function processConfiguration(ConfigurationInterface $configuration, array $configs)
  89. {
  90. $processor = new Processor();
  91. return $processor->processConfiguration($configuration, $configs);
  92. }
  93. /**
  94. * {@inheritDoc}
  95. */
  96. public function getConfiguration(array $config, ContainerBuilder $container)
  97. {
  98. $reflected = new \ReflectionClass($this);
  99. $namespace = $reflected->getNamespaceName();
  100. $class = $namespace . '\\Configuration';
  101. if (class_exists($class)) {
  102. if (!method_exists($class, '__construct')) {
  103. $configuration = new $class();
  104. return $configuration;
  105. }
  106. }
  107. return null;
  108. }
  109. }