Skip to content

Commit

Permalink
Merge pull request #140 from gregurco/add_options
Browse files Browse the repository at this point in the history
Add options and improve existent
  • Loading branch information
Florian Preusner committed Oct 31, 2017
2 parents 07e9693 + 9485db1 commit 03927ad
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 55 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ eight_points_guzzle:

...
```
All these settings are optional.
Allowed options: headers, allow_redirects, auth, query, curl, cert, connect_timeout, debug, decode_content, delay, form_params, multipart, sink, http_errors, expect, ssl_key, stream, synchronous, timeout, verify, cookies, proxy, version. All these settings are optional.
Description for all options and examples of parameters can be found [here][4].

Using services in controller (eight_points_guzzle.client.**api_crm** represents the client name of the yaml config and is an instance of GuzzleHttp\Client):
``` php
Expand All @@ -119,8 +120,8 @@ new EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle([
```

### Known and Supported Plugins
- [gregurco/GuzzleBundleWssePlugin][4]
- [gregurco/GuzzleBundleCachePlugin][5]
- [gregurco/GuzzleBundleWssePlugin][5]
- [gregurco/GuzzleBundleCachePlugin][6]

----

Expand Down Expand Up @@ -162,7 +163,7 @@ services:
## Contributing
👍 If you would like to contribute to the project, please read the [CONTRIBUTING.md](CONTRIBUTING.md).
🎉 Thanks to the [contributors][6] who participated in this project.
🎉 Thanks to the [contributors][7] who participated in this project.
----
Expand All @@ -173,6 +174,7 @@ This bundle is released under the [MIT license](src/Resources/meta/LICENSE)
[1]: http://guzzlephp.org/
[2]: http://semver.org/
[3]: https://packagist.org/packages/eightpoints/guzzle-bundle
[4]: https://github.com/gregurco/GuzzleBundleWssePlugin
[5]: https://github.com/gregurco/GuzzleBundleCachePlugin
[6]: https://github.com/8p/GuzzleBundle/graphs/contributors
[4]: http://docs.guzzlephp.org/en/latest/request-options.html
[5]: https://github.com/gregurco/GuzzleBundleWssePlugin
[6]: https://github.com/gregurco/GuzzleBundleCachePlugin
[7]: https://github.com/8p/GuzzleBundle/graphs/contributors
130 changes: 86 additions & 44 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public function __construct(string $alias, bool $debug = false, array $plugins =
* @version 1.0
* @since 2013-10
*
* @return TreeBuilder
* @throws \RuntimeException
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
*/
public function getConfigTreeBuilder() : TreeBuilder
{
Expand All @@ -65,40 +66,58 @@ public function getConfigTreeBuilder() : TreeBuilder
*
* @since 2015-07
*
* @return \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition
* @throws \RuntimeException
*
* @return \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition
*/
private function createClientsNode()
private function createClientsNode() : ArrayNodeDefinition
{
$builder = new TreeBuilder();
$node = $builder->root('clients');

// Filtering function to cast scalar values to boolean
$boolFilter = function ($value) {
return (bool)$value;
};

$nodeChildren = $node->useAttributeAsKey('name')
->prototype('array')
->children();

$nodeChildren->scalarNode('class')->defaultValue('%eight_points_guzzle.http_client.class%')->end()
->scalarNode('base_url')->defaultValue(null)->end()

->scalarNode('base_url')
->defaultValue(null)
->validate()
->ifTrue(function ($v) {
return !is_string($v);
})
->thenInvalid('base_url can be: string')
->end()
->end()
->arrayNode('options')
->children()
->arrayNode('headers')
->normalizeKeys(false)
->prototype('scalar')
->end()
->end()
->arrayNode('auth')
->prototype('scalar')
->variableNode('allow_redirects')
->validate()
->ifTrue(function ($v) {
return !is_array($v) && !is_bool($v);
})
->thenInvalid('allow_redirects can be: bool or array')
->end()
->end()
->arrayNode('query')
->prototype('scalar')
->variableNode('auth')
->validate()
->ifTrue(function ($v) {
return !is_array($v) && !is_string($v);
})
->thenInvalid('auth can be: string or array')
->end()
->end()
->variableNode('query')
->validate()
->ifTrue(function ($v) {
return !is_string($v) && !is_array($v);
})
->thenInvalid('query can be: string or array')
->end()
->end()
->arrayNode('curl')
Expand Down Expand Up @@ -131,51 +150,67 @@ private function createClientsNode()
->variableNode('cert')
->validate()
->ifTrue(function ($v) {
return !is_string($v) && (!is_array($v) || count($v) != 2);
return !is_string($v) && (!is_array($v) || count($v) !== 2);
})
->thenInvalid('A string or a two entries array required')
->thenInvalid('cert can be: string or array with two entries (path and password)')
->end()
->end()
->scalarNode('connect_timeout')->end()
->booleanNode('debug')
->beforeNormalization()
->ifString()->then($boolFilter)
->floatNode('connect_timeout')->end()
->booleanNode('debug')->end()
->variableNode('decode_content')
->validate()
->ifTrue(function ($v) {
return !is_string($v) && !is_bool($v);
})
->thenInvalid('decode_content can be: bool or string (gzip, compress, deflate, etc...)')
->end()
->end()
->booleanNode('decode_content')
->beforeNormalization()
->ifString()->then($boolFilter)
->floatNode('delay')->end()
->arrayNode('form_params')
->prototype('variable')
->end()
->end()
->scalarNode('delay')->end()
->booleanNode('http_errors')
->beforeNormalization()
->ifString()->then($boolFilter)
->arrayNode('multipart')
->prototype('variable')
->end()
->end()
->scalarNode('expect')->end()
->scalarNode('ssl_key')->end()
->booleanNode('stream')
->beforeNormalization()
->ifString()->then($boolFilter)
->scalarNode('sink')
->validate()
->ifTrue(function ($v) {
return !is_string($v);
})
->thenInvalid('sink can be: string')
->end()
->end()
->booleanNode('synchronous')
->beforeNormalization()
->ifString()->then($boolFilter)
->booleanNode('http_errors')->end()
->variableNode('expect')
->validate()
->ifTrue(function ($v) {
return !is_bool($v) && !is_int($v);
})
->thenInvalid('expect can be: bool or int')
->end()
->end()
->scalarNode('timeout')->end()
->booleanNode('verify')
->beforeNormalization()
->ifString()->then($boolFilter)
->variableNode('ssl_key')
->validate()
->ifTrue(function ($v) {
return !is_string($v) && (!is_array($v) || count($v) !== 2);
})
->thenInvalid('ssl_key can be: string or array with two entries (path and password)')
->end()
->end()
->booleanNode('cookies')
->beforeNormalization()
->ifString()->then($boolFilter)
->booleanNode('stream')->end()
->booleanNode('synchronous')->end()
->floatNode('timeout')->end()
->variableNode('verify')
->validate()
->ifTrue(function ($v) {
return !is_bool($v) && !is_string($v);
})
->thenInvalid('verify can be: bool or string')
->end()
->end()
->booleanNode('cookies')->end()
->arrayNode('proxy')
->beforeNormalization()
->ifString()
Expand All @@ -197,7 +232,14 @@ private function createClientsNode()
->end()
->end()
->end()
->scalarNode('version')->end()
->scalarNode('version')
->validate()
->ifTrue(function ($v) {
return !is_string($v) && !is_float($v);
})
->thenInvalid('version can be: string or float')
->end()
->end()
->end()
->end();

Expand Down
Loading

0 comments on commit 03927ad

Please sign in to comment.