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

Skip to content

Commit 13afd2b

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 598a21d commit 13afd2b

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
@@ -1979,13 +1979,17 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
19791979
->ifTrue(fn ($v) => !empty($v['query']) && !isset($v['base_uri']))
19801980
->thenInvalid('"query" applies to "base_uri" but no base URI is defined.')
19811981
->end()
1982+
->validate()
1983+
->ifTrue(fn ($v) => (isset($v['base_uri']) && \is_array($v['base_uri'])) && !isset($v['retry_failed']))
1984+
->thenInvalid('"base_uri" can only be an array if "retry_failed" is defined.')
1985+
->end()
19821986
->children()
19831987
->scalarNode('scope')
19841988
->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.')
19851989
->cannotBeEmpty()
19861990
->end()
1987-
->scalarNode('base_uri')
1988-
->info('The URI to resolve relative URLs, following rules in RFC 3985, section 2.')
1991+
->variableNode('base_uri')
1992+
->info('The URI(s) to resolve relative URLs, following rules in RFC 3985, section 2.')
19891993
->cannotBeEmpty()
19901994
->end()
19911995
->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
@@ -668,6 +668,7 @@
668668
<xsd:element name="resolve" type="http_resolve" minOccurs="0" maxOccurs="unbounded" />
669669
<xsd:element name="header" type="http_header" minOccurs="0" maxOccurs="unbounded" />
670670
<xsd:element name="peer-fingerprint" type="fingerprint" minOccurs="0" maxOccurs="unbounded" />
671+
<xsd:element name="base-uri" type="http_client_base_uri" minOccurs="0" maxOccurs="unbounded" />
671672
<xsd:element name="retry-failed" type="http_client_retry_failed" minOccurs="0" maxOccurs="1" />
672673
<xsd:element name="extra" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded" />
673674
</xsd:choice>
@@ -694,6 +695,7 @@
694695
<xsd:element name="resolve" type="http_resolve" minOccurs="0" maxOccurs="unbounded" />
695696
<xsd:element name="header" type="http_header" minOccurs="0" maxOccurs="unbounded" />
696697
<xsd:element name="peer-fingerprint" type="fingerprint" minOccurs="0" maxOccurs="unbounded" />
698+
<xsd:element name="base-uri" type="http_client_base_uri" minOccurs="0" maxOccurs="unbounded" />
697699
<xsd:element name="retry-failed" type="http_client_retry_failed" minOccurs="0" maxOccurs="1" />
698700
<xsd:element name="extra" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded" />
699701
</xsd:choice>
@@ -747,6 +749,10 @@
747749
<xsd:attribute name="code" type="xsd:integer" />
748750
</xsd:complexType>
749751

752+
<xsd:complexType name="http_client_base_uri" mixed="true">
753+
<xsd:attribute name="key" type="xsd:string" />
754+
</xsd:complexType>
755+
750756
<xsd:complexType name="http_query" mixed="true">
751757
<xsd:attribute name="key" type="xsd:string" />
752758
</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
@@ -22,6 +22,10 @@
2222
'base_uri' => 'http://example.com',
2323
'retry_failed' => ['multiplier' => 4],
2424
],
25+
'bar' => [
26+
'base_uri' => ['http://a.example.com', 'http://b.example.com'],
27+
'retry_failed' => ['max_retries' => 4],
28+
],
2529
],
2630
],
2731
]);

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
@@ -26,6 +26,11 @@
2626
<framework:scoped-client name="foo" base-uri="http://example.com">
2727
<framework:retry-failed multiplier="4"/>
2828
</framework:scoped-client>
29+
<framework:scoped-client name="bar">
30+
<framework:base-uri>http://a.example.com</framework:base-uri>
31+
<framework:base-uri>http://a.example.com</framework:base-uri>
32+
<framework:retry-failed max-retries="3"/>
33+
</framework:scoped-client>
2934
</framework:http-client>
3035
</framework:config>
3136
</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
@@ -21,3 +21,9 @@ framework:
2121
base_uri: http://example.com
2222
retry_failed:
2323
multiplier: 4
24+
bar:
25+
base_uri:
26+
- http://a.example.com
27+
- http://b.example.com
28+
retry_failed:
29+
max_retries: 3

0 commit comments

Comments
 (0)
0