Skip to content

Commit 280412c

Browse files
committed
Allow to configure the QueryDefaultsPlugin
1 parent aacd615 commit 280412c

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
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+
## Unreleased
6+
7+
### Added
8+
9+
- Allow to configure the `QueryDefaultsPlugin`
10+
511
## 1.12.0 - 2018-10-25
612

713
### Added

DependencyInjection/Configuration.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,19 @@ private function createClientPluginNode()
390390
->end()
391391
->end()
392392
->end()
393+
->arrayNode('query_defaults')
394+
->canBeEnabled()
395+
->info('Sets query parameters to default value if they are not present in the request.')
396+
->fixXmlConfig('parameter')
397+
->children()
398+
->arrayNode('parameters')
399+
->info('List of query parameters. Names and values must not be url encoded as the plugin will encode them.')
400+
->normalizeKeys(false)
401+
->useAttributeAsKey('name')
402+
->prototype('scalar')->end()
403+
->end()
404+
->end()
405+
->end()
393406
->end()
394407
->end();
395408

DependencyInjection/HttplugExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ private function configurePluginByName($name, Definition $definition, array $con
232232

233233
break;
234234

235+
case 'query_defaults':
236+
$definition->replaceArgument(0, $config['parameters']);
237+
238+
break;
239+
235240
default:
236241
throw new \InvalidArgumentException(sprintf('Internal exception: Plugin %s is not handled', $name));
237242
}

Resources/config/plugins.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
<service id="httplug.plugin.header_remove" class="Http\Client\Common\Plugin\HeaderRemovePlugin" public="false" abstract="true">
5454
<argument/>
5555
</service>
56+
<service id="httplug.plugin.query_defaults" class="Http\Client\Common\Plugin\QueryDefaultsPlugin" public="false" abstract="true">
57+
<argument/>
58+
</service>
5659

5760
</services>
5861
</container>

Tests/Unit/DependencyInjection/HttplugExtensionTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public function testClientPlugins()
102102
'headers' => ['X-FOO'],
103103
],
104104
],
105+
[
106+
'query_defaults' => [
107+
'parameters' => ['locale' => 'en'],
108+
],
109+
],
105110
[
106111
'authentication' => [
107112
'my_basic' => [
@@ -129,6 +134,7 @@ public function testClientPlugins()
129134
'httplug.client.acme.plugin.header_defaults',
130135
'httplug.client.acme.plugin.header_set',
131136
'httplug.client.acme.plugin.header_remove',
137+
'httplug.client.acme.plugin.query_defaults',
132138
'httplug.client.acme.authentication.my_basic',
133139
'httplug.client.acme.plugin.cache',
134140
];

0 commit comments

Comments
 (0)