src/AppBundle/DependencyInjection/AppExtension.php line 12

Open in your IDE?
  1. <?php
  2. namespace AppBundle\DependencyInjection;
  3. use Symfony\Component\DependencyInjection\ContainerBuilder;
  4. use Symfony\Component\Config\FileLocator;
  5. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  6. use Symfony\Component\DependencyInjection\Loader;
  7. use Symfony\Component\Console\Application;
  8. use Symfony\Component\DependencyInjection\Container;
  9. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  10. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  11. class AppExtension extends Extension
  12. {
  13.     use ContainerAwareTrait;
  14.     protected $name;
  15.     protected $extension;
  16.     protected $path;
  17.     private $namespace;
  18.     
  19.     public function load(array $configsContainerBuilder $container)
  20.     {
  21.         
  22.         // $configuration = new Configuration();
  23.         // $config = $this->processConfiguration($configuration, $configs);
  24.         
  25.         $loader = new Loader\YamlFileLoader(
  26.             $container,
  27.             new FileLocator(__DIR__.'/../Resources/config')
  28.         );
  29.         $loader->load('services.yml');
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     public function boot()
  35.     {
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public function shutdown()
  41.     {
  42.     }
  43.     /**
  44.      * {@inheritdoc}
  45.      *
  46.      * This method can be overridden to register compilation passes,
  47.      * other extensions, ...
  48.      */
  49.     public function build(ContainerBuilder $container)
  50.     {
  51.     }
  52.     /**
  53.      * Returns the bundle's container extension.
  54.      *
  55.      * @return ExtensionInterface|null
  56.      *
  57.      * @throws \LogicException
  58.      */
  59.     public function getContainerExtension()
  60.     {
  61.         if (null === $this->extension) {
  62.             $extension $this->createContainerExtension();
  63.             if (null !== $extension) {
  64.                 if (!$extension instanceof ExtensionInterface) {
  65.                     throw new \LogicException(sprintf('Extension "%s" must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.'get_debug_type($extension)));
  66.                 }
  67.                 // check naming convention
  68.                 $basename preg_replace('/Bundle$/'''$this->getName());
  69.                 $expectedAlias Container::underscore($basename);
  70.                 if ($expectedAlias != $extension->getAlias()) {
  71.                     throw new \LogicException(sprintf('Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.'$expectedAlias$extension->getAlias()));
  72.                 }
  73.                 $this->extension $extension;
  74.             } else {
  75.                 $this->extension false;
  76.             }
  77.         }
  78.         return $this->extension ?: null;
  79.     }
  80.     /**
  81.      * {@inheritdoc}
  82.      */
  83.     public function getNamespace():string
  84.     {
  85.         if (null === $this->namespace) {
  86.             $this->parseClassName();
  87.         }
  88.         return $this->namespace;
  89.     }
  90.     /**
  91.      * {@inheritdoc}
  92.      */
  93.     public function getPath()
  94.     {
  95.         if (null === $this->path) {
  96.             $reflected = new \ReflectionObject($this);
  97.             $this->path \dirname($reflected->getFileName());
  98.         }
  99.         return $this->path;
  100.     }
  101.     /**
  102.      * Returns the bundle name (the class short name).
  103.      */
  104.     final public function getName(): string
  105.     {
  106.         if (null === $this->name) {
  107.             $this->parseClassName();
  108.         }
  109.         return $this->name;
  110.     }
  111.     public function registerCommands(Application $application)
  112.     {
  113.     }
  114.     /**
  115.      * Returns the bundle's container extension class.
  116.      *
  117.      * @return string
  118.      */
  119.     protected function getContainerExtensionClass()
  120.     {
  121.         $basename preg_replace('/Bundle$/'''$this->getName());
  122.         return $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
  123.     }
  124.     /**
  125.      * Creates the bundle's container extension.
  126.      *
  127.      * @return ExtensionInterface|null
  128.      */
  129.     protected function createContainerExtension()
  130.     {
  131.         return class_exists($class $this->getContainerExtensionClass()) ? new $class() : null;
  132.     }
  133.     private function parseClassName()
  134.     {
  135.         $pos strrpos(static::class, '\\');
  136.         $this->namespace false === $pos '' substr(static::class, 0$pos);
  137.         if (null === $this->name) {
  138.             $this->name false === $pos ? static::class : substr(static::class, $pos 1);
  139.         }
  140.     }
  141. }