HttpClientPass.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. if (0 < \func_num_args()) {
  22. trigger_deprecation('symfony/http-client', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
  23. }
  24. $this->clientTag = $clientTag;
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function process(ContainerBuilder $container)
  30. {
  31. if (!$container->hasDefinition('data_collector.http_client')) {
  32. return;
  33. }
  34. foreach ($container->findTaggedServiceIds($this->clientTag) as $id => $tags) {
  35. $container->register('.debug.'.$id, TraceableHttpClient::class)
  36. ->setArguments([new Reference('.debug.'.$id.'.inner'), new Reference('debug.stopwatch', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)])
  37. ->addTag('kernel.reset', ['method' => 'reset'])
  38. ->setDecoratedService($id, null, 5);
  39. $container->getDefinition('data_collector.http_client')
  40. ->addMethodCall('registerClient', [$id, new Reference('.debug.'.$id)]);
  41. }
  42. }
  43. }