Skip to content

Commit 5c4db94

Browse files
enekochandbu
authored andcommitted
Add AddPathPlugin support (#256)
fix #255
1 parent 75c85e1 commit 5c4db94

File tree

9 files changed

+45
-1
lines changed

9 files changed

+45
-1
lines changed

CHANGELOG.md

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

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

5+
## 1.10.0 (unreleased) - 2018-03-09
6+
7+
### Added
8+
9+
- Allow to configure the `AddPathPlugin` per client, under the `add_path` configuration key.
10+
511
## 1.9.0 - 2018-03-06
612

713
### Added

DependencyInjection/Configuration.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,18 @@ private function createClientPluginNode()
298298
->end()
299299
->end()
300300
->end()
301+
->arrayNode('add_path')
302+
->canBeEnabled()
303+
->addDefaultsIfNotSet()
304+
->info('Add a base path to the request.')
305+
->children()
306+
->scalarNode('path')
307+
->info('Path to be added, e.g. /api/v1')
308+
->isRequired()
309+
->cannotBeEmpty()
310+
->end()
311+
->end()
312+
->end()
301313
->arrayNode('base_uri')
302314
->canBeEnabled()
303315
->addDefaultsIfNotSet()

DependencyInjection/HttplugExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ private function configurePluginByName($name, Definition $definition, array $con
207207
'replace' => $config['replace'],
208208
]);
209209

210+
break;
211+
case 'add_path':
212+
$pathUriService = $serviceId.'.path_uri';
213+
$this->createUri($container, $pathUriService, $config['path']);
214+
$definition->replaceArgument(0, new Reference($pathUriService));
215+
210216
break;
211217
case 'base_uri':
212218
$baseUriService = $serviceId.'.base_uri';

Resources/config/plugins.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<argument/>
3535
<argument/>
3636
</service>
37+
<service id="httplug.plugin.add_path" class="Http\Client\Common\Plugin\AddPathPlugin" public="false" abstract="true">
38+
<argument/>
39+
</service>
3740
<service id="httplug.plugin.base_uri" class="Http\Client\Common\Plugin\BaseUriPlugin" public="false" abstract="true">
3841
<argument/>
3942
<argument/>

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+
'add_path' => [
29+
'path' => '/api/v1',
30+
],
31+
],
2732
[
2833
'base_uri' => [
2934
'uri' => 'http://localhost',

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+
<add-path path="/api/v1"/>
24+
</plugin>
2225
<plugin>
2326
<base-uri uri="http://localhost"/>
2427
</plugin>

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+
add_path:
23+
path: /api/v1
2124
-
2225
base_uri:
2326
uri: http://localhost

Tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ public function testSupportsAllConfigFormats()
134134
'replace' => false,
135135
],
136136
],
137+
[
138+
'add_path' => [
139+
'enabled' => true,
140+
'path' => '/api/v1',
141+
],
142+
],
137143
[
138144
'base_uri' => [
139145
'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.9-dev"
84+
"dev-master": "1.10-dev"
8585
}
8686
}
8787
}

0 commit comments

Comments
 (0)