HttpClientPass.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. /**
  19. * {@inheritdoc}
  20. */
  21. public function process(ContainerBuilder $container)
  22. {
  23. if (!$container->hasDefinition('data_collector.http_client')) {
  24. return;
  25. }
  26. foreach ($container->findTaggedServiceIds('http_client.client') as $id => $tags) {
  27. $container->register('.debug.'.$id, TraceableHttpClient::class)
  28. ->setArguments([new Reference('.debug.'.$id.'.inner'), new Reference('debug.stopwatch', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)])
  29. ->addTag('kernel.reset', ['method' => 'reset'])
  30. ->setDecoratedService($id, null, 5);
  31. $container->getDefinition('data_collector.http_client')
  32. ->addMethodCall('registerClient', [$id, new Reference('.debug.'.$id)]);
  33. }
  34. }
  35. }