Skip to content

Commit 5ea9284

Browse files
llaakkkkdbu
authored andcommitted
Add BaseUriPlugin support. fix #235 (#240)
1 parent 9c1ff72 commit 5ea9284

File tree

9 files changed

+54
-4
lines changed

9 files changed

+54
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
## 1.9.0 (unreleased) - 2017-01-12
6+
- Allow to configure the `BaseUriPlugin` per client, under the `base_uri` configuration key.
7+
58
## 1.8.1 - 2017-12-06
69

710
### Fixed

DependencyInjection/Configuration.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,22 @@ private function createClientPluginNode()
298298
->end()
299299
->end()
300300
->end()
301+
->arrayNode('base_uri')
302+
->canBeEnabled()
303+
->addDefaultsIfNotSet()
304+
->info('Set a base URI to the request.')
305+
->children()
306+
->scalarNode('uri')
307+
->info('Base Uri including protocol, optionally the port number and prepend path, e.g. https://api.local:8000/api')
308+
->isRequired()
309+
->cannotBeEmpty()
310+
->end()
311+
->scalarNode('replace')
312+
->info('Whether to replace the host if request already specifies one')
313+
->defaultValue(false)
314+
->end()
315+
->end()
316+
->end()
301317
->arrayNode('header_append')
302318
->canBeEnabled()
303319
->info('Append headers to the request. If the header already exists the value will be appended to the current value.')

DependencyInjection/HttplugExtension.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,18 @@ private function configurePluginByName($name, Definition $definition, array $con
199199
/* client specific plugins */
200200

201201
case 'add_host':
202-
$uriService = $serviceId.'.host_uri';
203-
$this->createUri($container, $uriService, $config['host']);
204-
$definition->replaceArgument(0, new Reference($uriService));
202+
$hostUriService = $serviceId.'.host_uri';
203+
$this->createUri($container, $hostUriService, $config['host']);
204+
$definition->replaceArgument(0, new Reference($hostUriService));
205+
$definition->replaceArgument(1, [
206+
'replace' => $config['replace'],
207+
]);
208+
209+
break;
210+
case 'base_uri':
211+
$baseUriService = $serviceId.'.base_uri';
212+
$this->createUri($container, $baseUriService, $config['uri']);
213+
$definition->replaceArgument(0, new Reference($baseUriService));
205214
$definition->replaceArgument(1, [
206215
'replace' => $config['replace'],
207216
]);

Resources/config/plugins.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
<argument/>
3535
<argument/>
3636
</service>
37+
<service id="httplug.plugin.base_uri" class="Http\Client\Common\Plugin\BaseUriPlugin" public="false" abstract="true">
38+
<argument/>
39+
<argument/>
40+
</service>
3741
<service id="httplug.plugin.header_append" class="Http\Client\Common\Plugin\HeaderAppendPlugin" public="false" abstract="true">
3842
<argument/>
3943
</service>

Tests/Resources/Fixtures/config/full.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
'host' => 'http://localhost',
2525
],
2626
],
27+
[
28+
'base_uri' => [
29+
'uri' => 'http://localhost',
30+
],
31+
],
2732
[
2833
'header_set' => [
2934
'headers' => [

Tests/Resources/Fixtures/config/full.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<plugin>
2020
<add-host host="http://localhost"/>
2121
</plugin>
22+
<plugin>
23+
<base-uri uri="http://localhost"/>
24+
</plugin>
2225
<plugin>
2326
<header-set>
2427
<header name="X-FOO">bar</header>

Tests/Resources/Fixtures/config/full.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ httplug:
1818
-
1919
add_host:
2020
host: http://localhost
21+
-
22+
base_uri:
23+
uri: http://localhost
2124
-
2225
header_set:
2326
headers:

Tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ public function testSupportsAllConfigFormats()
134134
'replace' => false,
135135
],
136136
],
137+
[
138+
'base_uri' => [
139+
'enabled' => true,
140+
'uri' => 'http://localhost',
141+
'replace' => false,
142+
],
143+
],
137144
[
138145
'header_set' => [
139146
'enabled' => true,

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
},
8282
"extra": {
8383
"branch-alias": {
84-
"dev-master": "1.8-dev"
84+
"dev-master": "1.9-dev"
8585
}
8686
}
8787
}

0 commit comments

Comments
 (0)