vendor/eightpoints/guzzle-bundle/src/EightPointsGuzzleBundle.php line 12

Open in your IDE?
  1. <?php
  2. namespace EightPoints\Bundle\GuzzleBundle;
  3. use EightPoints\Bundle\GuzzleBundle\DependencyInjection\EightPointsGuzzleExtension;
  4. use EightPoints\Bundle\GuzzleBundle\DependencyInjection\Compiler\EventHandlerCompilerPass;
  5. use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
  6. use Symfony\Component\HttpKernel\Bundle\Bundle;
  7. use Symfony\Component\DependencyInjection\ContainerBuilder;
  8. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  9. class EightPointsGuzzleBundle extends Bundle
  10. {
  11.     /** @var \EightPoints\Bundle\GuzzleBundle\PluginInterface[] */
  12.     protected $plugins = [];
  13.     /**
  14.      * @param \EightPoints\Bundle\GuzzleBundle\PluginInterface[] $plugins
  15.      */
  16.     public function __construct(array $plugins = [])
  17.     {
  18.         foreach ($plugins as $plugin) {
  19.             $this->registerPlugin($plugin);
  20.         }
  21.     }
  22.     /**
  23.      * Build EightPointsGuzzleBundle
  24.      *
  25.      * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  26.      *
  27.      * @return void
  28.      */
  29.     public function build(ContainerBuilder $container)
  30.     {
  31.         parent::build($container);
  32.         foreach ($this->plugins as $plugin) {
  33.             $plugin->build($container);
  34.         }
  35.     }
  36.     /**
  37.      * Overwrite getContainerExtension
  38.      *  - no naming convention of alias needed
  39.      *  - extension class can be moved easily now
  40.      *
  41.      * @return \Symfony\Component\DependencyInjection\Extension\ExtensionInterface The container extension
  42.      */
  43.     public function getContainerExtension() : ExtensionInterface
  44.     {
  45.         if ($this->extension === null) {
  46.             $this->extension = new EightPointsGuzzleExtension($this->plugins);
  47.         }
  48.         return $this->extension;
  49.     }
  50.     /**
  51.      * @inheritdoc
  52.      */
  53.     public function boot()
  54.     {
  55.         foreach ($this->plugins as $plugin) {
  56.             $plugin->boot();
  57.         }
  58.     }
  59.     /**
  60.      * @param \EightPoints\Bundle\GuzzleBundle\PluginInterface $plugin
  61.      *
  62.      * @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  63.      *
  64.      * @return void
  65.      */
  66.     protected function registerPlugin(PluginInterface $plugin) : void
  67.     {
  68.         // Check plugins name duplication
  69.         foreach ($this->plugins as $registeredPlugin) {
  70.             if ($registeredPlugin->getPluginName() === $plugin->getPluginName()) {
  71.                 throw new InvalidConfigurationException(sprintf(
  72.                     'Trying to connect two plugins with same name: %s',
  73.                     $plugin->getPluginName()
  74.                 ));
  75.             }
  76.         }
  77.         $this->plugins[] = $plugin;
  78.     }
  79. }