AbstractBundle.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Bundle;
  11. use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
  12. use Symfony\Component\DependencyInjection\Container;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Extension\ConfigurableExtensionInterface;
  15. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  16. use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
  17. /**
  18. * A Bundle that provides configuration hooks.
  19. *
  20. * @author Yonel Ceruto <yonelceruto@gmail.com>
  21. */
  22. abstract class AbstractBundle extends Bundle implements ConfigurableExtensionInterface
  23. {
  24. protected string $extensionAlias = '';
  25. public function configure(DefinitionConfigurator $definition): void
  26. {
  27. }
  28. public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
  29. {
  30. }
  31. public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
  32. {
  33. }
  34. public function getContainerExtension(): ?ExtensionInterface
  35. {
  36. if ('' === $this->extensionAlias) {
  37. $this->extensionAlias = Container::underscore(preg_replace('/Bundle$/', '', $this->getName()));
  38. }
  39. return $this->extension ??= new BundleExtension($this, $this->extensionAlias);
  40. }
  41. public function getPath(): string
  42. {
  43. if (null === $this->path) {
  44. $reflected = new \ReflectionObject($this);
  45. // assume the modern directory structure by default
  46. $this->path = \dirname($reflected->getFileName(), 2);
  47. }
  48. return $this->path;
  49. }
  50. }