vendor/php-http/httplug-bundle/src/Collector/PluginClientFactoryListener.php line 44

Open in your IDE?
  1. <?php
  2. namespace Http\HttplugBundle\Collector;
  3. use Http\Client\Common\PluginClientFactory as DefaultPluginClientFactory;
  4. use Symfony\Component\EventDispatcher\Event as LegacyEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Kernel;
  7. use Symfony\Contracts\EventDispatcher\Event;
  8. if (Kernel::MAJOR_VERSION >= 5) {
  9.     \class_alias(Event::class, 'Http\HttplugBundle\Collector\PluginClientFactoryListenerEventClass');
  10. } else {
  11.     \class_alias(LegacyEvent::class, 'Http\HttplugBundle\Collector\PluginClientFactoryListenerEventClass');
  12. }
  13. /**
  14.  * This subscriber ensures that every PluginClient created when using Http\Client\Common\PluginClientFactory without
  15.  * using the Symfony dependency injection container uses the Http\HttplugBundle\Collector\PluginClientFactory factory
  16.  * when profiling is enabled. This allows 0 config profiling of third party libraries which use HTTPlug.
  17.  *
  18.  * @author Fabien Bourigault <bourigaultfabien@gmail.com>
  19.  *
  20.  * @internal
  21.  */
  22. final class PluginClientFactoryListener implements EventSubscriberInterface
  23. {
  24.     /**
  25.      * @var PluginClientFactory
  26.      */
  27.     private $factory;
  28.     /**
  29.      * @param PluginClientFactory $factory
  30.      */
  31.     public function __construct(PluginClientFactory $factory)
  32.     {
  33.         $this->factory $factory;
  34.     }
  35.     /**
  36.      * Make sure to profile clients created using PluginClientFactory.
  37.      */
  38.     public function onEvent(PluginClientFactoryListenerEventClass $e)
  39.     {
  40.         DefaultPluginClientFactory::setFactory([$this->factory'createClient']);
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public static function getSubscribedEvents()
  46.     {
  47.         return [
  48.             'kernel.request' => ['onEvent'1024],
  49.             'console.command' => ['onEvent'1024],
  50.         ];
  51.     }
  52. }