From 63bae4378ac62b656efbf8243657b74e80ef2084 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 25 Jul 2016 03:29:21 +0200 Subject: [PATCH 1/3] Added batch client support --- DependencyInjection/Configuration.php | 6 +++++- DependencyInjection/HttplugExtension.php | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d8430a5e..e5702168 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -138,7 +138,7 @@ protected function configureClients(ArrayNodeDefinition $root) ->validate() ->ifTrue(function ($clients) { foreach ($clients as $name => $config) { - return $config['flexible_client'] && $config['http_methods_client']; + return $config['flexible_client'] && $config['http_methods_client'] && $config['batch_client']; } return false; @@ -160,6 +160,10 @@ protected function configureClients(ArrayNodeDefinition $root) ->defaultFalse() ->info('Set to true to get the client wrapped in a HttpMethodsClient which emulates provides functions for HTTP verbs.') ->end() + ->booleanNode('batch_client') + ->defaultFalse() + ->info('Set to true to get the client wrapped in a BatchClient which allows you to send multiple request at the same time.') + ->end() ->arrayNode('plugins') ->info('A list of service ids of plugins. The order is important.') ->prototype('scalar')->end() diff --git a/DependencyInjection/HttplugExtension.php b/DependencyInjection/HttplugExtension.php index 0e2ef183..f1b78988 100644 --- a/DependencyInjection/HttplugExtension.php +++ b/DependencyInjection/HttplugExtension.php @@ -2,6 +2,7 @@ namespace Http\HttplugBundle\DependencyInjection; +use Http\Client\Common\BatchClient; use Http\Client\Common\FlexibleHttpClient; use Http\Client\Common\HttpMethodsClient; use Http\Client\Common\Plugin\AuthenticationPlugin; @@ -265,6 +266,15 @@ function ($id) { ->setDecoratedService($serviceId) ; } + + if ($arguments['batch_client']) { + $container + ->register($serviceId.'.batch_client', BatchClient::class) + ->setArguments([new Reference($serviceId.'.batch_client.inner')]) + ->setPublic(false) + ->setDecoratedService($serviceId) + ; + } } /** From 5e03c1861d9d3f9cbfe6e572a534137f335cecb0 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 25 Jul 2016 03:36:49 +0200 Subject: [PATCH 2/3] Validate config properly --- DependencyInjection/Configuration.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index e5702168..dd8c8194 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -138,7 +138,8 @@ protected function configureClients(ArrayNodeDefinition $root) ->validate() ->ifTrue(function ($clients) { foreach ($clients as $name => $config) { - return $config['flexible_client'] && $config['http_methods_client'] && $config['batch_client']; + // Make sure we only allow one of these to be true + return (bool) $config['flexible_client'] + (bool) $config['http_methods_client'] + (bool) $config['batch_client'] >= 2; } return false; From 49dfd174539aeb9fd01236d2cdfccda181c07a11 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 25 Jul 2016 03:37:21 +0200 Subject: [PATCH 3/3] Comment about BatchClient in changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbbd0d38..2177afaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ## UNRELEASED +### Added + +- Support for BatchClient + ### Changed - All clients are registered with the PluginClient. (even in production)