From 027bd2d604e1869b22306ff47114a812ce577746 Mon Sep 17 00:00:00 2001 From: enekochan Date: Thu, 8 Mar 2018 00:26:11 +0100 Subject: [PATCH 1/3] Add AddPathPlugin support. ISSUE-255 --- CHANGELOG.md | 6 ++++++ DependencyInjection/Configuration.php | 16 ++++++++++++++++ DependencyInjection/HttplugExtension.php | 9 +++++++++ Resources/config/plugins.xml | 4 ++++ Tests/Resources/Fixtures/config/full.php | 5 +++++ Tests/Resources/Fixtures/config/full.xml | 3 +++ Tests/Resources/Fixtures/config/full.yml | 3 +++ .../DependencyInjection/ConfigurationTest.php | 7 +++++++ 8 files changed, 53 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99f94432..614678d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 1.9.1 (unreleased) - 2018-03-09 + +### Added + +- Allow to configure the `AddPathPlugin` per client, under the `add_path` configuration key. + ## 1.9.0 - 2018-03-06 ### Added diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 8905895f..bdb62924 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -298,6 +298,22 @@ private function createClientPluginNode() ->end() ->end() ->end() + ->arrayNode('add_path') + ->canBeEnabled() + ->addDefaultsIfNotSet() + ->info('Add a base path to the request.') + ->children() + ->scalarNode('path') + ->info('Path to be added, e.g. /api/v1') + ->isRequired() + ->cannotBeEmpty() + ->end() + ->scalarNode('replace') + ->info('Whether to replace the path if request already specifies one') + ->defaultValue(false) + ->end() + ->end() + ->end() ->arrayNode('base_uri') ->canBeEnabled() ->addDefaultsIfNotSet() diff --git a/DependencyInjection/HttplugExtension.php b/DependencyInjection/HttplugExtension.php index 083f3dd4..0035c555 100644 --- a/DependencyInjection/HttplugExtension.php +++ b/DependencyInjection/HttplugExtension.php @@ -207,6 +207,15 @@ private function configurePluginByName($name, Definition $definition, array $con 'replace' => $config['replace'], ]); + break; + case 'add_path': + $pathUriService = $serviceId.'.path_uri'; + $this->createUri($container, $pathUriService, $config['path']); + $definition->replaceArgument(0, new Reference($pathUriService)); + $definition->replaceArgument(1, [ + 'replace' => $config['replace'], + ]); + break; case 'base_uri': $baseUriService = $serviceId.'.base_uri'; diff --git a/Resources/config/plugins.xml b/Resources/config/plugins.xml index f0bab813..af45b70f 100644 --- a/Resources/config/plugins.xml +++ b/Resources/config/plugins.xml @@ -34,6 +34,10 @@ + + + + diff --git a/Tests/Resources/Fixtures/config/full.php b/Tests/Resources/Fixtures/config/full.php index b3956aed..e1233c8d 100644 --- a/Tests/Resources/Fixtures/config/full.php +++ b/Tests/Resources/Fixtures/config/full.php @@ -24,6 +24,11 @@ 'host' => 'http://localhost', ], ], + [ + 'add_path' => [ + 'path' => '/api/v1', + ], + ], [ 'base_uri' => [ 'uri' => 'http://localhost', diff --git a/Tests/Resources/Fixtures/config/full.xml b/Tests/Resources/Fixtures/config/full.xml index 95287667..ef9eaba7 100644 --- a/Tests/Resources/Fixtures/config/full.xml +++ b/Tests/Resources/Fixtures/config/full.xml @@ -19,6 +19,9 @@ + + + diff --git a/Tests/Resources/Fixtures/config/full.yml b/Tests/Resources/Fixtures/config/full.yml index a4545541..8b56b9b3 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 + - + add_path: + path: /api/v1 - base_uri: uri: http://localhost diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index 13283ab8..17e7d3f4 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -134,6 +134,13 @@ public function testSupportsAllConfigFormats() 'replace' => false, ], ], + [ + 'add_path' => [ + 'enabled' => true, + 'path' => '/api/v1', + 'replace' => false, + ], + ], [ 'base_uri' => [ 'enabled' => true, From 5d9991b5c36904abd94f7cc700091f1c19ad1f88 Mon Sep 17 00:00:00 2001 From: enekochan Date: Thu, 8 Mar 2018 10:53:00 +0100 Subject: [PATCH 2/3] Fix semver version --- CHANGELOG.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 614678d7..09192a07 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.1 (unreleased) - 2018-03-09 +## 1.10.0 (unreleased) - 2018-03-09 ### Added diff --git a/composer.json b/composer.json index d2f16bbf..a9b4eabf 100644 --- a/composer.json +++ b/composer.json @@ -81,7 +81,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.9-dev" + "dev-master": "1.10-dev" } } } From d76e9c9bd410ba866f6595be035f2656040c5ee0 Mon Sep 17 00:00:00 2001 From: enekochan Date: Thu, 8 Mar 2018 11:25:39 +0100 Subject: [PATCH 3/3] Fix replace --- DependencyInjection/Configuration.php | 4 ---- DependencyInjection/HttplugExtension.php | 3 --- Resources/config/plugins.xml | 1 - Tests/Unit/DependencyInjection/ConfigurationTest.php | 1 - 4 files changed, 9 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index bdb62924..cb43df30 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -308,10 +308,6 @@ private function createClientPluginNode() ->isRequired() ->cannotBeEmpty() ->end() - ->scalarNode('replace') - ->info('Whether to replace the path if request already specifies one') - ->defaultValue(false) - ->end() ->end() ->end() ->arrayNode('base_uri') diff --git a/DependencyInjection/HttplugExtension.php b/DependencyInjection/HttplugExtension.php index 0035c555..0186f794 100644 --- a/DependencyInjection/HttplugExtension.php +++ b/DependencyInjection/HttplugExtension.php @@ -212,9 +212,6 @@ private function configurePluginByName($name, Definition $definition, array $con $pathUriService = $serviceId.'.path_uri'; $this->createUri($container, $pathUriService, $config['path']); $definition->replaceArgument(0, new Reference($pathUriService)); - $definition->replaceArgument(1, [ - 'replace' => $config['replace'], - ]); break; case 'base_uri': diff --git a/Resources/config/plugins.xml b/Resources/config/plugins.xml index af45b70f..b9b3f2dc 100644 --- a/Resources/config/plugins.xml +++ b/Resources/config/plugins.xml @@ -36,7 +36,6 @@ - diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index 17e7d3f4..52ca3c74 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -138,7 +138,6 @@ public function testSupportsAllConfigFormats() 'add_path' => [ 'enabled' => true, 'path' => '/api/v1', - 'replace' => false, ], ], [