Extension.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace Symfony\Component\HttpKernel\DependencyInjection;
  3. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  4. use Symfony\Component\DependencyInjection\ContainerBuilder;
  5. use Symfony\Component\DependencyInjection\Container;
  6. /*
  7. * This file is part of the Symfony framework.
  8. *
  9. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  10. *
  11. * This source file is subject to the MIT license that is bundled
  12. * with this source code in the file LICENSE.
  13. */
  14. /**
  15. * Provides useful features shared by many extensions.
  16. *
  17. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  18. */
  19. abstract class Extension implements ExtensionInterface
  20. {
  21. protected $classes = array();
  22. protected $classMap = array();
  23. /**
  24. * Gets the classes to cache.
  25. *
  26. * @return array An array of classes
  27. */
  28. public function getClassesToCompile()
  29. {
  30. return $this->classes;
  31. }
  32. /**
  33. * Adds classes to the class cache.
  34. *
  35. * @param array $classes An array of classes
  36. */
  37. protected function addClassesToCompile(array $classes)
  38. {
  39. $this->classes = array_merge($this->classes, $classes);
  40. }
  41. /**
  42. * Gets the autoload class map.
  43. *
  44. * @return array An array of classes
  45. */
  46. public function getAutoloadClassMap()
  47. {
  48. return $this->classMap;
  49. }
  50. /**
  51. * Adds classes to the autoload class map.
  52. *
  53. * @param array $classes An array of classes
  54. */
  55. public function addClassesToAutoloadMap(array $classes)
  56. {
  57. $this->classMap = array_merge($this->classMap, $classes);
  58. }
  59. /**
  60. * Returns the base path for the XSD files.
  61. *
  62. * @return string The XSD base path
  63. */
  64. public function getXsdValidationBasePath()
  65. {
  66. return false;
  67. }
  68. /**
  69. * Returns the namespace to be used for this extension (XML namespace).
  70. *
  71. * @return string The XML namespace
  72. */
  73. public function getNamespace()
  74. {
  75. return false;
  76. }
  77. /**
  78. * Returns the recommended alias to use in XML.
  79. *
  80. * This alias is also the mandatory prefix to use when using YAML.
  81. *
  82. * @return string The alias
  83. */
  84. public function getAlias()
  85. {
  86. $className = get_class($this);
  87. if (substr($className, -9) != 'Extension') {
  88. throw new \BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.');
  89. }
  90. $classBaseName = substr(strrchr($className, '\\'), 1, -9);
  91. return Container::underscore($classBaseName);
  92. }
  93. }