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

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