Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbc39d2

Browse files
committed
wire setLogger() calls for registered HTTP clients
1 parent 924e4d8 commit bbc39d2

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,7 +2499,8 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
24992499
new Reference($name.'.uri_template.inner'),
25002500
new Reference('http_client.uri_template_expander', ContainerInterface::NULL_ON_INVALID_REFERENCE),
25012501
$defaultUriTemplateVars,
2502-
]);
2502+
])
2503+
->addMethodCall('setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]);
25032504

25042505
$container->registerAliasForArgument($name, HttpClientInterface::class);
25052506

@@ -2541,7 +2542,8 @@ private function registerThrottlingHttpClient(string $rateLimiter, string $name,
25412542
$container
25422543
->register($name.'.throttling', ThrottlingHttpClient::class)
25432544
->setDecoratedService($name, null, 15) // higher priority than RetryableHttpClient (10)
2544-
->setArguments([new Reference($name.'.throttling.inner'), new Reference($name.'.throttling.limiter')]);
2545+
->setArguments([new Reference($name.'.throttling.inner'), new Reference($name.'.throttling.limiter')])
2546+
->addMethodCall('setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)]);
25452547
}
25462548

25472549
private function registerRetryableHttpClient(array $options, string $name, ContainerBuilder $container): void

src/Symfony/Bundle/FrameworkBundle/Resources/config/http_client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
service('http_client.uri_template_expander')->nullOnInvalid(),
7878
abstract_arg('default vars'),
7979
])
80+
->call('setLogger', [service('logger')->ignoreOnInvalid()])
8081

8182
->set('http_client.uri_template_expander.guzzle', \Closure::class)
8283
->factory([\Closure::class, 'fromCallable'])

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"symfony/form": "^6.4|^7.0",
4949
"symfony/expression-language": "^6.4|^7.0",
5050
"symfony/html-sanitizer": "^6.4|^7.0",
51-
"symfony/http-client": "^6.4|^7.0",
51+
"symfony/http-client": "^7.1",
5252
"symfony/lock": "^6.4|^7.0",
5353
"symfony/mailer": "^6.4|^7.0",
5454
"symfony/messenger": "^6.4|^7.0",
@@ -84,7 +84,7 @@
8484
"symfony/console": "<6.4",
8585
"symfony/dotenv": "<6.4",
8686
"symfony/dom-crawler": "<6.4",
87-
"symfony/http-client": "<6.4",
87+
"symfony/http-client": "<7.1",
8888
"symfony/form": "<6.4",
8989
"symfony/lock": "<6.4",
9090
"symfony/mailer": "<6.4",

src/Symfony/Component/HttpClient/RetryableHttpClient.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @author Jérémy Derussé <[email protected]>
3030
*/
31-
class RetryableHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface
31+
class RetryableHttpClient implements HttpClientInterface, ResetInterface
3232
{
3333
use AsyncDecoratorTrait;
3434

@@ -46,6 +46,10 @@ public function __construct(HttpClientInterface $client, ?RetryStrategyInterface
4646
$this->strategy = $strategy ?? new GenericRetryStrategy();
4747
$this->maxRetries = $maxRetries;
4848
$this->logger = $logger;
49+
50+
if (null !== $logger && $this->client instanceof LoggerAwareInterface) {
51+
$this->client->setLogger($logger);
52+
}
4953
}
5054

5155
public function withOptions(array $options): static
@@ -164,14 +168,6 @@ public function request(string $method, string $url, array $options = []): Respo
164168
});
165169
}
166170

167-
public function setLogger(LoggerInterface $logger): void
168-
{
169-
$this->logger = $logger;
170-
if ($this->client instanceof LoggerAwareInterface) {
171-
$this->client->setLogger($logger);
172-
}
173-
}
174-
175171
private function getDelayFromHeader(array $headers): ?int
176172
{
177173
if (null !== $after = $headers['retry-after'][0] ?? null) {

0 commit comments

Comments
 (0)