Skip to content

Commit bb6ac80

Browse files
Nyholmsagikazarmark
authored andcommitted
Added batch client support (#103)
* Added batch client support * Validate config properly * Comment about BatchClient in changelog
1 parent 30ca50d commit bb6ac80

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
## UNRELEASED
55

6+
### Added
7+
8+
- Support for BatchClient
9+
610
### Changed
711

812
- All clients are registered with the PluginClient (even in production)

DependencyInjection/Configuration.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ protected function configureClients(ArrayNodeDefinition $root)
138138
->validate()
139139
->ifTrue(function ($clients) {
140140
foreach ($clients as $name => $config) {
141-
return $config['flexible_client'] && $config['http_methods_client'];
141+
// Make sure we only allow one of these to be true
142+
return (bool) $config['flexible_client'] + (bool) $config['http_methods_client'] + (bool) $config['batch_client'] >= 2;
142143
}
143144

144145
return false;
@@ -160,6 +161,10 @@ protected function configureClients(ArrayNodeDefinition $root)
160161
->defaultFalse()
161162
->info('Set to true to get the client wrapped in a HttpMethodsClient which emulates provides functions for HTTP verbs.')
162163
->end()
164+
->booleanNode('batch_client')
165+
->defaultFalse()
166+
->info('Set to true to get the client wrapped in a BatchClient which allows you to send multiple request at the same time.')
167+
->end()
163168
->arrayNode('plugins')
164169
->info('A list of service ids of plugins. The order is important.')
165170
->prototype('scalar')->end()

DependencyInjection/HttplugExtension.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Http\HttplugBundle\DependencyInjection;
44

5+
use Http\Client\Common\BatchClient;
56
use Http\Client\Common\FlexibleHttpClient;
67
use Http\Client\Common\HttpMethodsClient;
78
use Http\Client\Common\Plugin\AuthenticationPlugin;
@@ -265,6 +266,15 @@ function ($id) {
265266
->setDecoratedService($serviceId)
266267
;
267268
}
269+
270+
if ($arguments['batch_client']) {
271+
$container
272+
->register($serviceId.'.batch_client', BatchClient::class)
273+
->setArguments([new Reference($serviceId.'.batch_client.inner')])
274+
->setPublic(false)
275+
->setDecoratedService($serviceId)
276+
;
277+
}
268278
}
269279

270280
/**

0 commit comments

Comments
 (0)