vendor/ibexa/core/src/bundle/IO/DependencyInjection/IbexaIOExtension.php line 123

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. namespace Ibexa\Bundle\IO\DependencyInjection;
  7. use ArrayObject;
  8. use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
  9. use Symfony\Component\Config\FileLocator;
  10. use Symfony\Component\DependencyInjection\ContainerBuilder;
  11. use Symfony\Component\DependencyInjection\Loader;
  12. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  13. /**
  14.  * This is the class that loads and manages your bundle configuration.
  15.  *
  16.  * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
  17.  */
  18. class IbexaIOExtension extends Extension
  19. {
  20.     public const EXTENSION_NAME 'ibexa_io';
  21.     /** @var \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory[]|\ArrayObject */
  22.     private $metadataHandlerFactories;
  23.     /** @var \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory[]|\ArrayObject */
  24.     private $binarydataHandlerFactories;
  25.     public function __construct()
  26.     {
  27.         $this->metadataHandlerFactories = new ArrayObject();
  28.         $this->binarydataHandlerFactories = new ArrayObject();
  29.     }
  30.     /**
  31.      * Registers a metadata handler configuration $factory for handler with $alias.
  32.      *
  33.      * @param string $alias
  34.      * @param \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory $factory
  35.      */
  36.     public function addMetadataHandlerFactory($aliasConfigurationFactory $factory)
  37.     {
  38.         $this->metadataHandlerFactories[$alias] = $factory;
  39.     }
  40.     /**
  41.      * Registers a binarydata handler configuration $factory for handler with $alias.
  42.      *
  43.      * @param string $alias
  44.      * @param \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory $factory
  45.      */
  46.     public function addBinarydataHandlerFactory($aliasConfigurationFactory $factory)
  47.     {
  48.         $this->binarydataHandlerFactories[$alias] = $factory;
  49.     }
  50.     /**
  51.      * @return \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory[]|\ArrayObject
  52.      */
  53.     public function getMetadataHandlerFactories()
  54.     {
  55.         return $this->metadataHandlerFactories;
  56.     }
  57.     /**
  58.      * @return \Ibexa\Bundle\IO\DependencyInjection\ConfigurationFactory[]|\ArrayObject
  59.      */
  60.     public function getBinarydataHandlerFactories()
  61.     {
  62.         return $this->binarydataHandlerFactories;
  63.     }
  64.     public function getAlias()
  65.     {
  66.         return self::EXTENSION_NAME;
  67.     }
  68.     /**
  69.      * {@inheritdoc}
  70.      */
  71.     public function load(array $configsContainerBuilder $container)
  72.     {
  73.         $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ '/../Resources/config'));
  74.         $configuration $this->getConfiguration($configs$container);
  75.         $config $this->processConfiguration($configuration$configs);
  76.         $loader->load('io.yml');
  77.         $loader->load('default_settings.yml');
  78.         $this->processHandlers($container$config'metadata_handlers');
  79.         $this->processHandlers($container$config'binarydata_handlers');
  80.     }
  81.     /**
  82.      * Processes the config key $key, and registers the result in ez_io.$key.
  83.      *
  84.      * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  85.      * @param string $key Configuration key, either binarydata or metadata
  86.      */
  87.     private function processHandlers(ContainerBuilder $container$config$key)
  88.     {
  89.         $handlers = [];
  90.         if (isset($config[$key])) {
  91.             foreach ($config[$key] as $name => $value) {
  92.                 if (isset($handlers[$name])) {
  93.                     throw new InvalidConfigurationException("A $key called $name already exists");
  94.                 }
  95.                 $handlerConfig current($value);
  96.                 $handlerConfig['type'] = key($value);
  97.                 $handlerConfig['name'] = $name;
  98.                 $handlers[$name] = $handlerConfig;
  99.             }
  100.         }
  101.         $container->setParameter("ibexa.io.{$key}"$handlers);
  102.     }
  103.     public function getConfiguration(array $configContainerBuilder $container)
  104.     {
  105.         $configuration = new Configuration();
  106.         $configuration->setMetadataHandlerFactories($this->getMetadataHandlerFactories());
  107.         $configuration->setBinarydataHandlerFactories($this->getBinarydataHandlerFactories());
  108.         return $configuration;
  109.     }
  110. }
  111. class_alias(IbexaIOExtension::class, 'eZ\Bundle\EzPublishIOBundle\DependencyInjection\EzPublishIOExtension');