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\EightPointsGuzzleBundlePlugin[] */
  12.     protected $plugins = [];
  13.     /**
  14.      * @param \EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundlePlugin[] $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.         $container->addCompilerPass(new EventHandlerCompilerPass());
  36.     }
  37.     /**
  38.      * Overwrite getContainerExtension
  39.      *  - no naming convention of alias needed
  40.      *  - extension class can be moved easily now
  41.      *
  42.      * @return \Symfony\Component\DependencyInjection\Extension\ExtensionInterface The container extension
  43.      */
  44.     public function getContainerExtension() : ExtensionInterface
  45.     {
  46.         if ($this->extension === null) {
  47.             $this->extension = new EightPointsGuzzleExtension($this->plugins);
  48.         }
  49.         return $this->extension;
  50.     }
  51.     /**
  52.      * @inheritdoc
  53.      */
  54.     public function boot()
  55.     {
  56.         foreach ($this->plugins as $plugin) {
  57.             $plugin->boot();
  58.         }
  59.     }
  60.     /**
  61.      * @param \EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundlePlugin $plugin
  62.      *
  63.      * @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  64.      *
  65.      * @return void
  66.      */
  67.     protected function registerPlugin(EightPointsGuzzleBundlePlugin $plugin)
  68.     {
  69.         // Check plugins name duplication
  70.         foreach ($this->plugins as $registeredPlugin) {
  71.             if ($registeredPlugin->getPluginName() === $plugin->getPluginName()) {
  72.                 throw new InvalidConfigurationException(sprintf(
  73.                     'Trying to connect two plugins with same name: %s',
  74.                     $plugin->getPluginName()
  75.                 ));
  76.             }
  77.         }
  78.         $this->plugins[] = $plugin;
  79.     }
  80. }