Skip to content

Add BaseUriPlugin support. ISSUE-235 #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

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

## 1.9.0 (unreleased) - 2017-01-12
- Allow to configure the `BaseUriPlugin` per client, under the `base_uri` configuration key.

## 1.8.1 - 2017-12-06

### Fixed
Expand Down
16 changes: 16 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,22 @@ private function createClientPluginNode()
->end()
->end()
->end()
->arrayNode('base_uri')
->canBeEnabled()
->addDefaultsIfNotSet()
->info('Set a base URI to the request.')
->children()
->scalarNode('uri')
->info('Base Uri including protocol, optionally the port number and prepend path, e.g. https://api.local:8000/api')
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('replace')
->info('Whether to replace the host if request already specifies one')
->defaultValue(false)
->end()
->end()
->end()
->arrayNode('header_append')
->canBeEnabled()
->info('Append headers to the request. If the header already exists the value will be appended to the current value.')
Expand Down
15 changes: 12 additions & 3 deletions DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,18 @@ private function configurePluginByName($name, Definition $definition, array $con
/* client specific plugins */

case 'add_host':
$uriService = $serviceId.'.host_uri';
$this->createUri($container, $uriService, $config['host']);
$definition->replaceArgument(0, new Reference($uriService));
$hostUriService = $serviceId.'.host_uri';
$this->createUri($container, $hostUriService, $config['host']);
$definition->replaceArgument(0, new Reference($hostUriService));
$definition->replaceArgument(1, [
'replace' => $config['replace'],
]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing break

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you still need to add a break; here, its the reason why the tests fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbu I fixed all review, can you please review my PR?


break;
case 'base_uri':
$baseUriService = $serviceId.'.base_uri';
$this->createUri($container, $baseUriService, $config['uri']);
$definition->replaceArgument(0, new Reference($baseUriService));
$definition->replaceArgument(1, [
'replace' => $config['replace'],
]);
Expand Down
4 changes: 4 additions & 0 deletions Resources/config/plugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<argument/>
<argument/>
</service>
<service id="httplug.plugin.base_uri" class="Http\Client\Common\Plugin\BaseUriPlugin" public="false" abstract="true">
<argument/>
<argument/>
</service>
<service id="httplug.plugin.header_append" class="Http\Client\Common\Plugin\HeaderAppendPlugin" public="false" abstract="true">
<argument/>
</service>
Expand Down
5 changes: 5 additions & 0 deletions Tests/Resources/Fixtures/config/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
'host' => 'http://localhost',
],
],
[
'base_uri' => [
'uri' => 'http://localhost',
],
],
[
'header_set' => [
'headers' => [
Expand Down
3 changes: 3 additions & 0 deletions Tests/Resources/Fixtures/config/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<plugin>
<add-host host="http://localhost"/>
</plugin>
<plugin>
<base-uri uri="http://localhost"/>
</plugin>
<plugin>
<header-set>
<header name="X-FOO">bar</header>
Expand Down
3 changes: 3 additions & 0 deletions Tests/Resources/Fixtures/config/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ httplug:
-
add_host:
host: http://localhost
-
base_uri:
uri: http://localhost
-
header_set:
headers:
Expand Down
7 changes: 7 additions & 0 deletions Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ public function testSupportsAllConfigFormats()
'replace' => false,
],
],
[
'base_uri' => [
'enabled' => true,
'uri' => 'http://localhost',
'replace' => false,
],
],
[
'header_set' => [
'enabled' => true,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.8-dev"
"dev-master": "1.9-dev"
}
}
}