From c51720a40232615d3e13dfc7e74bd38eebacfb16 Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Tue, 19 Dec 2017 11:56:13 +0200 Subject: [PATCH 1/8] Add BaseUriPlugin support. ISSUE-235 --- DependencyInjection/Configuration.php | 16 ++++++++++++++++ DependencyInjection/HttplugExtension.php | 7 +++++++ Resources/config/plugins.xml | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 227df718..6e06f14d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -298,6 +298,22 @@ private function createClientPluginNode() ->end() ->end() ->end() + ->arrayNode('base_uri') + ->canBeEnabled() + ->addDefaultsIfNotSet() + ->info('Set scheme, host and port in the request URI.') + ->children() + ->scalarNode('host') + ->info('Host name including protocol and optionally the port number, e.g. https://api.local:8000') + ->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.') diff --git a/DependencyInjection/HttplugExtension.php b/DependencyInjection/HttplugExtension.php index e8afe492..d1ba5cc1 100644 --- a/DependencyInjection/HttplugExtension.php +++ b/DependencyInjection/HttplugExtension.php @@ -203,6 +203,13 @@ private function configurePluginByName($name, Definition $definition, array $con $definition->replaceArgument(1, [ 'replace' => $config['replace'], ]); + case 'base_uri': + $baseService = $serviceId.'.host_uri'; + $this->createUri($container, $baseService, $config['host']); + $definition->replaceArgument(0, new Reference($uriService)); + $definition->replaceArgument(1, [ + 'replace' => $config['replace'], + ]); break; case 'header_append': diff --git a/Resources/config/plugins.xml b/Resources/config/plugins.xml index d921f910..f0bab813 100644 --- a/Resources/config/plugins.xml +++ b/Resources/config/plugins.xml @@ -34,6 +34,10 @@ + + + + From f7aa1435aadd212211f10c25acd679b2fcffa72c Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Thu, 28 Dec 2017 02:20:54 +0200 Subject: [PATCH 2/8] Add fixes after review: fixed code, add info to CHANGELOG.md --- CHANGELOG.md | 1 + DependencyInjection/Configuration.php | 6 +++--- DependencyInjection/HttplugExtension.php | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e908090..4061b98c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee - Any third party library using `Http\Client\Common\PluginClientFactory` to create `Http\Client\Common\PluginClient` instances now gets zero config profiling. - `Http\HttplugBundle\Collector\Collector::reset()` +- BaseUriPlugin support ### Changed diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 6e06f14d..8905895f 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -301,10 +301,10 @@ private function createClientPluginNode() ->arrayNode('base_uri') ->canBeEnabled() ->addDefaultsIfNotSet() - ->info('Set scheme, host and port in the request URI.') + ->info('Set a base URI to the request.') ->children() - ->scalarNode('host') - ->info('Host name including protocol and optionally the port number, e.g. https://api.local:8000') + ->scalarNode('uri') + ->info('Base Uri including protocol, optionally the port number and prepend path, e.g. https://api.local:8000/api') ->isRequired() ->cannotBeEmpty() ->end() diff --git a/DependencyInjection/HttplugExtension.php b/DependencyInjection/HttplugExtension.php index d1ba5cc1..15fadb00 100644 --- a/DependencyInjection/HttplugExtension.php +++ b/DependencyInjection/HttplugExtension.php @@ -204,8 +204,8 @@ private function configurePluginByName($name, Definition $definition, array $con 'replace' => $config['replace'], ]); case 'base_uri': - $baseService = $serviceId.'.host_uri'; - $this->createUri($container, $baseService, $config['host']); + $baseService = $serviceId.'.base_uri'; + $this->createUri($container, $baseService, $config['uri']); $definition->replaceArgument(0, new Reference($uriService)); $definition->replaceArgument(1, [ 'replace' => $config['replace'], From b1257a04db6e23f1abd22dcd5bf113a9a8b9a8ab Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Fri, 12 Jan 2018 16:14:11 +0100 Subject: [PATCH 3/8] Add new info to CHANGELOG.md with version 1.9.0 --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de057267..2a613485 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 1.9.0 - 2017-01-12 +- Configured the `BaseUriPlugin` per client, under the `base_uri` configuration key. + ## 1.8.1 - 2017-12-06 ### Fixed @@ -17,7 +20,6 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee - Any third party library using `Http\Client\Common\PluginClientFactory` to create `Http\Client\Common\PluginClient` instances now gets zero config profiling. - `Http\HttplugBundle\Collector\Collector::reset()` -- BaseUriPlugin support ### Changed From 75ab4b3bf918db78708af3473870c74c2901aebe Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Mon, 15 Jan 2018 12:29:28 +0100 Subject: [PATCH 4/8] Add new info to CHANGELOG.md with version 1.9.0-unreleased and ad missing break --- CHANGELOG.md | 2 +- DependencyInjection/HttplugExtension.php | 14 +++++++------- composer.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a613485..44230ed4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. -## 1.9.0 - 2017-01-12 +## 1.9.0 (unreleased) - 2017-01-12 - Configured the `BaseUriPlugin` per client, under the `base_uri` configuration key. ## 1.8.1 - 2017-12-06 diff --git a/DependencyInjection/HttplugExtension.php b/DependencyInjection/HttplugExtension.php index 7b238274..19f51d90 100644 --- a/DependencyInjection/HttplugExtension.php +++ b/DependencyInjection/HttplugExtension.php @@ -199,20 +199,20 @@ 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'], ]); + break; case 'base_uri': - $baseService = $serviceId.'.base_uri'; - $this->createUri($container, $baseService, $config['uri']); - $definition->replaceArgument(0, new Reference($uriService)); + $baseUriService = $serviceId.'.base_uri'; + $this->createUri($container, $baseUriService, $config['uri']); + $definition->replaceArgument(0, new Reference($baseUriService)); $definition->replaceArgument(1, [ 'replace' => $config['replace'], ]); - break; case 'header_append': case 'header_defaults': diff --git a/composer.json b/composer.json index 7c38a6b3..9df5b982 100644 --- a/composer.json +++ b/composer.json @@ -82,7 +82,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.8-dev" + "dev-master": "1.9-dev" } } } From e22007b885e736a3c9906cfbfb87cad259fb0122 Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Mon, 15 Jan 2018 12:30:48 +0100 Subject: [PATCH 5/8] Fixed break style --- DependencyInjection/HttplugExtension.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DependencyInjection/HttplugExtension.php b/DependencyInjection/HttplugExtension.php index 19f51d90..8901d5be 100644 --- a/DependencyInjection/HttplugExtension.php +++ b/DependencyInjection/HttplugExtension.php @@ -205,6 +205,7 @@ private function configurePluginByName($name, Definition $definition, array $con $definition->replaceArgument(1, [ 'replace' => $config['replace'], ]); + break; case 'base_uri': $baseUriService = $serviceId.'.base_uri'; @@ -213,6 +214,7 @@ private function configurePluginByName($name, Definition $definition, array $con $definition->replaceArgument(1, [ 'replace' => $config['replace'], ]); + break; case 'header_append': case 'header_defaults': From cbde5eabef6c4151aabf90d674131ce58b642d0a Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Sun, 11 Feb 2018 21:39:43 +0200 Subject: [PATCH 6/8] Added configuration to tests --- Tests/Resources/Fixtures/config/full.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/Resources/Fixtures/config/full.yml b/Tests/Resources/Fixtures/config/full.yml index 460b472d..a4545541 100644 --- a/Tests/Resources/Fixtures/config/full.yml +++ b/Tests/Resources/Fixtures/config/full.yml @@ -18,6 +18,9 @@ httplug: - add_host: host: http://localhost + - + base_uri: + uri: http://localhost - header_set: headers: From 3b3629cf1c1c546a70082350132b2cb5a4cbc35d Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Tue, 13 Feb 2018 12:32:05 +0200 Subject: [PATCH 7/8] Added test configuration --- CHANGELOG.md | 2 +- Tests/Resources/Fixtures/config/full.php | 5 +++++ Tests/Unit/DependencyInjection/ConfigurationTest.php | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44230ed4..cb76412f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. ## 1.9.0 (unreleased) - 2017-01-12 -- Configured the `BaseUriPlugin` per client, under the `base_uri` configuration key. +- Allow to configure the `BaseUriPlugin` per client, under the `base_uri` configuration key. ## 1.8.1 - 2017-12-06 diff --git a/Tests/Resources/Fixtures/config/full.php b/Tests/Resources/Fixtures/config/full.php index 9b273542..b3956aed 100644 --- a/Tests/Resources/Fixtures/config/full.php +++ b/Tests/Resources/Fixtures/config/full.php @@ -24,6 +24,11 @@ 'host' => 'http://localhost', ], ], + [ + 'base_uri' => [ + 'uri' => 'http://localhost', + ], + ], [ 'header_set' => [ 'headers' => [ diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index 91200789..13283ab8 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -134,6 +134,13 @@ public function testSupportsAllConfigFormats() 'replace' => false, ], ], + [ + 'base_uri' => [ + 'enabled' => true, + 'uri' => 'http://localhost', + 'replace' => false, + ], + ], [ 'header_set' => [ 'enabled' => true, From 45380b263d5dce1f0f352ee63ba3de2f7bb76f09 Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Tue, 13 Feb 2018 16:58:54 +0200 Subject: [PATCH 8/8] Added config base_uri to full.xml --- Tests/Resources/Fixtures/config/full.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/Resources/Fixtures/config/full.xml b/Tests/Resources/Fixtures/config/full.xml index 9ef8e756..95287667 100644 --- a/Tests/Resources/Fixtures/config/full.xml +++ b/Tests/Resources/Fixtures/config/full.xml @@ -19,6 +19,9 @@ + + +
bar