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) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d8430a5e..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']; + // 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; @@ -160,6 +161,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) + ; + } } /**