HttpClientPass.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpClient\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\ContainerInterface;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. use Symfony\Component\HttpClient\TraceableHttpClient;
  16. final class HttpClientPass implements CompilerPassInterface
  17. {
  18. private $clientTag;
  19. public function __construct(string $clientTag = 'http_client.client')
  20. {
  21. $this->clientTag = $clientTag;
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function process(ContainerBuilder $container)
  27. {
  28. if (!$container->hasDefinition('data_collector.http_client')) {
  29. return;
  30. }
  31. foreach ($container->findTaggedServiceIds($this->clientTag) as $id => $tags) {
  32. $container->register('.debug.'.$id, TraceableHttpClient::class)
  33. ->setArguments([new Reference('.debug.'.$id.'.inner'), new Reference('debug.stopwatch', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)])
  34. ->setDecoratedService($id);
  35. $container->getDefinition('data_collector.http_client')
  36. ->addMethodCall('registerClient', [$id, new Reference('.debug.'.$id)]);
  37. }
  38. }
  39. }