Skip to content
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
21 changes: 21 additions & 0 deletions ClientFactory/AutoDiscoveryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Http\HttplugBundle\ClientFactory;

use Http\Discovery\HttpClientDiscovery;

/**
* Use auto discovery to find a HTTP client.
*
* @author Tobias Nyholm <[email protected]>
*/
class AutoDiscoveryFactory implements ClientFactory
{
/**
* {@inheritdoc}
*/
public function createClient(array $config = [])
{
return HttpClientDiscovery::find();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it worth to fallback to HttpAsyncClientDiscovery if HttpClientDiscovery does not returned any implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

I doubt it. I believe it is very rare that an async adapter/client does not implement HttpClient interface (not async).

}
}
8 changes: 7 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,15 @@ private function configureClients(ArrayNodeDefinition $root)
})
->thenInvalid('A http client can\'t be decorated with several of FlexibleHttpClient, HttpMethodsClient and BatchClient. Only one of the following options can be true. ("flexible_client", "http_methods_client", "batch_client")')
->end()
->validate()
->ifTrue(function ($config) {
return $config['factory'] === 'httplug.factory.auto' && !empty($config['config']);
})
->thenInvalid('If you want to use the "config" key you must also specify a valid "factory".')
->end()
->children()
->scalarNode('factory')
->isRequired()
->defaultValue('httplug.factory.auto')
->cannotBeEmpty()
->info('The service id of a factory to use when creating the adapter.')
->end()
Expand Down
6 changes: 6 additions & 0 deletions Resources/config/data-collector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
</service>

<!-- ClientFactories -->
<service id="httplug.collector.factory.auto" class="Http\HttplugBundle\Collector\ProfileClientFactory" decorates="httplug.factory.auto" public="false">
<argument type="service" id="httplug.collector.factory.auto.inner"/>
<argument type="service" id="httplug.collector.collector"/>
<argument type="service" id="httplug.collector.formatter"/>
<argument type="service" id="debug.stopwatch"/>
</service>
<service id="httplug.collector.factory.buzz" class="Http\HttplugBundle\Collector\ProfileClientFactory" decorates="httplug.factory.buzz" public="false">
<argument type="service" id="httplug.collector.factory.buzz.inner"/>
<argument type="service" id="httplug.collector.collector"/>
Expand Down
3 changes: 3 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<service id="Http\Client\HttpClient" alias="httplug.client" public="false" />

<!-- ClientFactories -->
<service id="httplug.factory.auto" class="Http\HttplugBundle\ClientFactory\AutoDiscoveryFactory" public="false">
<argument type="service" id="httplug.message_factory"/>
</service>
<service id="httplug.factory.buzz" class="Http\HttplugBundle\ClientFactory\BuzzFactory" public="false">
<argument type="service" id="httplug.message_factory"/>
</service>
Expand Down