80
80
use Symfony \Component \HttpClient \Retry \GenericRetryStrategy ;
81
81
use Symfony \Component \HttpClient \RetryableHttpClient ;
82
82
use Symfony \Component \HttpClient \ScopingHttpClient ;
83
+ use Symfony \Component \HttpClient \UriTemplateHttpClient ;
83
84
use Symfony \Component \HttpFoundation \Request ;
84
85
use Symfony \Component \HttpKernel \Attribute \AsController ;
85
86
use Symfony \Component \HttpKernel \CacheClearer \CacheClearerInterface ;
@@ -2338,6 +2339,8 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
2338
2339
$ options = $ config ['default_options ' ] ?? [];
2339
2340
$ retryOptions = $ options ['retry_failed ' ] ?? ['enabled ' => false ];
2340
2341
unset($ options ['retry_failed ' ]);
2342
+ $ defaultUriTemplateVars = $ options ['vars ' ] ?? [];
2343
+ unset($ options ['vars ' ]);
2341
2344
$ container ->getDefinition ('http_client ' )->setArguments ([$ options , $ config ['max_host_connections ' ] ?? 6 ]);
2342
2345
2343
2346
if (!$ hasPsr18 = ContainerBuilder::willBeAvailable ('psr/http-client ' , ClientInterface::class, ['symfony/framework-bundle ' , 'symfony/http-client ' ])) {
@@ -2349,11 +2352,38 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
2349
2352
$ container ->removeDefinition (HttpClient::class);
2350
2353
}
2351
2354
2352
- if ($ this ->readConfigEnabled ('http_client.retry_failed ' , $ container , $ retryOptions )) {
2355
+ if ($ hasRetryFailed = $ this ->readConfigEnabled ('http_client.retry_failed ' , $ container , $ retryOptions )) {
2353
2356
$ this ->registerRetryableHttpClient ($ retryOptions , 'http_client ' , $ container );
2354
2357
}
2355
2358
2356
- $ httpClientId = ($ retryOptions ['enabled ' ] ?? false ) ? 'http_client.retryable.inner ' : ($ this ->isInitializedConfigEnabled ('profiler ' ) ? '.debug.http_client.inner ' : 'http_client ' );
2359
+ if ($ hasUriTemplate = class_exists (UriTemplateHttpClient::class)) {
2360
+ $ uriTemplateExpanderId = null ;
2361
+ if (ContainerBuilder::willBeAvailable ('guzzlehttp/uri-template ' , \GuzzleHttp \UriTemplate \UriTemplate::class, [])) {
2362
+ $ uriTemplateExpanderId = 'http_client.uri_template_expander.guzzle ' ;
2363
+ } elseif (ContainerBuilder::willBeAvailable ('rize/uri-template ' , \Rize \UriTemplate::class, [])) {
2364
+ $ uriTemplateExpanderId = 'http_client.uri_template_expander.rize ' ;
2365
+ }
2366
+
2367
+ if ($ uriTemplateExpanderId ) {
2368
+ $ container ->setAlias ('http_client.uri_template_expander ' , $ uriTemplateExpanderId );
2369
+ }
2370
+
2371
+ $ container
2372
+ ->getDefinition ('http_client.uri_template ' )
2373
+ ->setArgument (2 , $ defaultUriTemplateVars );
2374
+ } elseif ($ defaultUriTemplateVars ) {
2375
+ throw new LogicException ('Support for URI template requires symfony/http-client 6.3 or higher, try upgrading. ' );
2376
+ }
2377
+
2378
+ $ httpClientId = 'http_client ' ;
2379
+ if ($ hasUriTemplate ) {
2380
+ $ httpClientId = 'http_client.uri_template.inner ' ;
2381
+ } elseif ($ hasRetryFailed ) {
2382
+ $ httpClientId = 'http_client.retryable.inner ' ;
2383
+ } elseif ($ this ->isInitializedConfigEnabled ('profiler ' )) {
2384
+ $ httpClientId = '.debug.http_client.inner ' ;
2385
+ }
2386
+
2357
2387
foreach ($ config ['scoped_clients ' ] as $ name => $ scopeConfig ) {
2358
2388
if ('http_client ' === $ name ) {
2359
2389
throw new InvalidArgumentException (sprintf ('Invalid scope name: "%s" is reserved. ' , $ name ));
@@ -2384,6 +2414,17 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
2384
2414
$ this ->registerRetryableHttpClient ($ retryOptions , $ name , $ container );
2385
2415
}
2386
2416
2417
+ if ($ hasUriTemplate ) {
2418
+ $ container
2419
+ ->register ($ name .'.uri_template ' , UriTemplateHttpClient::class)
2420
+ ->setDecoratedService ($ name , null , 7 ) // Between TraceableHttpClient (5) and RetryableHttpClient (10)
2421
+ ->setArguments ([
2422
+ new Reference ('.inner ' ),
2423
+ new Reference ('http_client.uri_template_expander ' ),
2424
+ $ defaultUriTemplateVars ,
2425
+ ]);
2426
+ }
2427
+
2387
2428
$ container ->registerAliasForArgument ($ name , HttpClientInterface::class);
2388
2429
2389
2430
if ($ hasPsr18 ) {
0 commit comments