Skip to content

Allow to configure the QueryDefaultsPlugin #284

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 1 commit into from
Nov 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## Unreleased

### Added

- Allow to configure the `QueryDefaultsPlugin`

## 1.12.0 - 2018-10-25

### Added
Expand Down
13 changes: 13 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,19 @@ private function createClientPluginNode()
->end()
->end()
->end()
->arrayNode('query_defaults')
->canBeEnabled()
->info('Sets query parameters to default value if they are not present in the request.')
->fixXmlConfig('parameter')
->children()
->arrayNode('parameters')
->info('List of query parameters. Names and values must not be url encoded as the plugin will encode them.')
->normalizeKeys(false)
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
->end();

Expand Down
5 changes: 5 additions & 0 deletions DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ private function configurePluginByName($name, Definition $definition, array $con

break;

case 'query_defaults':
$definition->replaceArgument(0, $config['parameters']);

break;

default:
throw new \InvalidArgumentException(sprintf('Internal exception: Plugin %s is not handled', $name));
}
Expand Down
3 changes: 3 additions & 0 deletions Resources/config/plugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<service id="httplug.plugin.header_remove" class="Http\Client\Common\Plugin\HeaderRemovePlugin" public="false" abstract="true">
<argument/>
</service>
<service id="httplug.plugin.query_defaults" class="Http\Client\Common\Plugin\QueryDefaultsPlugin" public="false" abstract="true">
<argument/>
</service>

</services>
</container>
6 changes: 6 additions & 0 deletions Tests/Unit/DependencyInjection/HttplugExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public function testClientPlugins()
'headers' => ['X-FOO'],
],
],
[
'query_defaults' => [
'parameters' => ['locale' => 'en'],
],
],
[
'authentication' => [
'my_basic' => [
Expand Down Expand Up @@ -129,6 +134,7 @@ public function testClientPlugins()
'httplug.client.acme.plugin.header_defaults',
'httplug.client.acme.plugin.header_set',
'httplug.client.acme.plugin.header_remove',
'httplug.client.acme.plugin.query_defaults',
'httplug.client.acme.authentication.my_basic',
'httplug.client.acme.plugin.cache',
];
Expand Down