Skip to content

Commit

Permalink
Added batch client support (#103)
Browse files Browse the repository at this point in the history
* Added batch client support

* Validate config properly

* Comment about BatchClient in changelog
  • Loading branch information
Nyholm authored and sagikazarmark committed Jul 25, 2016
1 parent 30ca50d commit bb6ac80
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

## UNRELEASED

### Added

- Support for BatchClient

### Changed

- All clients are registered with the PluginClient (even in production)
Expand Down
7 changes: 6 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
;
}
}

/**
Expand Down

0 comments on commit bb6ac80

Please sign in to comment.