10000 [FrameworkBundle] Fix config for array of base_uri in http_client · Tiriel/symfony@83ce0a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 83ce0a9

Browse files
committed
[FrameworkBundle] Fix config for array of base_uri in http_client
Allow array of `base_uri` in config for HttpClient keys, as per [comment in PR](symfony#49809 (comment)).
1 parent f99e1a0 commit 83ce0a9

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,13 +1901,17 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
19011901
->ifTrue(function ($v) { return !empty($v['query']) && !isset($v['base_uri']); })
19021902
->thenInvalid('"query" applies to "base_uri" but no base URI is defined.')
19031903
->end()
1904+
->validate()
1905+
->ifTrue(fn ($v) => (isset($v['base_uri']) && \is_array($v['base_uri'])) && !isset($v['retry_failed']))
1906+
->thenInvalid('"base_uri" can only be an array if "retry_failed" is defined.')
1907+
->end()
19041908
->children()
19051909
->scalarNode('scope')
19061910
->info('The regular expression that the request URL must match before adding the other options. When none is provided, the base URI is used instead.')
19071911
->cannotBeEmpty()
19081912
->end()
1909-
->scalarNode('base_uri')
1910-
->info('The URI to resolve relative URLs, following rules in RFC 3985, section 2.')
1913+
->variableNode('base_uri')
1914+
->info('The URI(s) to resolve relative URLs, following rules in RFC 3985, section 2.')
19111915
->cannotBeEmpty()
19121916
->end()
19131917
->scalarNode('auth_basic')

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@
665665
<xsd:element name="resolve" type="http_resolve" minOccurs="0" maxOccurs="unbounded" />
666666
<xsd:element name="header" type="http_header" minOccurs="0" maxOccurs="unbounded" />
667667
<xsd:element name="peer-fingerprint" type="fingerprint" minOccurs="0" maxOccurs="unbounded" />
668+
<xsd:element name="base-uri" type="http_client_base_uri" minOccurs="0" maxOccurs="unbounded" />
668669
<xsd:element name="retry-failed" type="http_client_retry_failed" minOccurs="0" maxOccurs="1" />
669670
<xsd:element name="extra" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded" />
670671
</xsd:choice>
@@ -691,6 +692,7 @@
691692
<xsd:element name="resolve" type="http_resolve" minOccurs="0" maxOccurs="unbounded" />
692693
<xsd:element name="header" type="http_header" minOccurs="0" maxOccurs="unbounded" />
693694
<xsd:element name="peer-fingerprint" type="fingerprint" minOccurs="0" maxOccurs="unbounded" />
695+
<xsd:element name="base-uri" type="http_client_base_uri" minOccurs="0" maxOccurs="unbounded" />
694696
<xsd:element name="retry-failed" type="http_client_retry_failed" minOccurs="0" maxOccurs="1" />
695697
<xsd:element name="extra" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded" />
696698
</xsd:choice>
@@ -744,6 +746,10 @@
744746
<xsd:attribute name="code" type="xsd:integer" />
745747
</xsd:complexType>
746748

749+
<xsd:complexType name="http_client_base_uri" mixed="true">
750+
<xsd:attribute name="key" type="xsd:string" />
751+
</xsd:complexType>
752+
747753
<xsd:complexType name="http_query" mixed="true">
748754
<xsd:attribute name="key" type="xsd:string" />
749755
</xsd:complexType>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/http_client_retry.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
'base_uri' => 'http://example.com',
2020
'retry_failed' => ['multiplier' => 4],
2121
],
22+
'bar' => [
23+
'base_uri' => ['http://a.example.com', 'http://b.example.com'],
24+
'retry_failed' => ['max_retries' => 4],
25+
],
2226
],
2327
],
2428
]);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/http_client_retry.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<framework:scoped-client name="foo" base-uri="http://example.com">
2525
<framework:retry-failed multiplier="4"/>
2626
</framework:scoped-client>
27+
<framework:scoped-client name="bar">
28+
<framework:base-uri>http://a.example.com</framework:base-uri>
29+
<framework:base-uri>http://a.example.com</framework:base-uri>
30+
<framework:retry-failed max-retries="3"/>
31+
</framework:scoped-client>
2732
</framework:http-client>
2833
</framework:config>
2934
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/http_client_retry.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ framework:
1717
base_uri: http://example.com
1818
retry_failed:
1919
multiplier: 4
20+
bar:
21+
base_uri:
22+
- http://a.example.com
23+
- http://b.example.com
24+
retry_failed:
25+
max_retries: 3

0 commit comments

Comments
 (0)
0