Skip to content

Commit

Permalink
Allow you to skip the factory keyword. (#170)
Browse files Browse the repository at this point in the history
* Allow you to skip the factory keyword.

* Updated exception message
  • Loading branch information
Nyholm authored May 22, 2017
1 parent ff80f90 commit 8096f29
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
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();
}
}
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

0 comments on commit 8096f29

Please sign in to comment.