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

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