8000 bug #36377 [HttpClient] Fix scoped client without query option config… · symfony/symfony@977276e · GitHub
[go: up one dir, main page]

Skip to content

Commit 977276e

Browse files
bug #36377 [HttpClient] Fix scoped client without query option configuration (X-Coder264)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] Fix scoped client without query option configuration | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | The `query` key default value is an [empty array](https://github.com/symfony/symfony/blob/v4.4.7/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php#L30) and because of that it is always set. Processing a configuration for a scoped HTTP client (which has a `scope` and does not have a `base_uri`) results in the configuration being invalid. The error message says that query parameters cannot be aplied to the base URI since it is not defined (which doesn't make sense since the query parameters don't exist because they are empty). Commits ------- a07578d [HttpClient] Fix scoped client without query option configuration
2 parents 6f19746 + a07578d commit 977276e

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode)
14821482
->thenInvalid('Either "scope" or "base_uri" should be defined.')
14831483
->end()
14841484
->validate()
1485-
->ifTrue(function ($v) { return isset($v['query']) && !isset($v['base_uri']); })
1485+
->ifTrue(function ($v) { return !empty($v['query']) && !isset($v['base_uri']); })
14861486
->thenInvalid('"query" applies to "base_uri" but no base URI is defined.')
14871487
->end()
14881488
->children()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'http_client' => [
5+
'scoped_clients' => [
6+
'foo' => [
7+
'scope' => '.*',
8+
],
9+
],
10+
],
11+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:http-client>
10+
<framework:scoped-client
11+
name="foo"
12+
scope=".*"
13+
/>
14+
</framework:http-client>
15+
</framework:config>
16+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
framework:
2+
http_client:
3+
scoped_clients:
4+
foo:
5+
scope: '.*'

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,14 @@ public function testHttpClientDefaultOptions()
15471547
$this->assertSame(ScopingHttpClient::class, $container->getDefinition('foo')->getClass());
15481548
}
15491549

1550+
public function testScopedHttpClientWithoutQueryOption()
1551+
{
1552+
$container = $this->createContainerFromFile('http_client_scoped_without_query_option');
1553+
1554+
$this->assertTrue($container->hasDefinition('foo'), 'should have the "foo" service.');
1555+
$this->assertSame(ScopingHttpClient::class, $container->getDefinition('foo')->getClass());
1556+
}
1557+
15501558
public function testHttpClientOverrideDefaultOptions()
15511559
{
15521560
$container = $this->createContainerFromFile('http_client_override_default_options');

0 commit comments

Comments
 (0)
0