Skip to content

Added batch client support #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member Author

@Nyholm Nyholm Jul 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cant use all of them the same time. That is why I limit them. (As we did before). This could be changed when we are doing behaviors (#91)

}

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