Skip to content

Commit 8d96317

Browse files
committed
Make it possible to create public httplug clients
1 parent 853c4f6 commit 8d96317

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

CHANGELOG.md

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

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
## 1.12.0 - 2018-10-24
6+
7+
### Added
8+
9+
- Add configuration option to create public clients
10+
511
## 1.11.0 - 2018-07-07
612

713
### Added

DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ private function configureClients(ArrayNodeDefinition $root)
195195
->defaultNull()
196196
->info('The service id of the client to use.')
197197
->end()
198+
->booleanNode('public')
199+
->defaultFalse()
200+
->info('Set true if you really cannot use dependency injection and need to make the client service public.')
201+
->end()
198202
->booleanNode('flexible_client')
199203
->defaultFalse()
200204
->info('Set to true to get the client wrapped in a FlexibleHttpClient which emulates async or sync behavior.')

DependencyInjection/HttplugExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,15 @@ private function configureClient(ContainerBuilder $container, $clientName, array
316316
$container
317317
->register($serviceId.'.client', HttpClient::class)
318318
->setFactory([new Reference($arguments['factory']), 'createClient'])
319-
->addArgument($arguments['config'])
320-
->setPublic(false);
319+
->addArgument($arguments['config']);
321320
} else {
322321
$container
323322
->setAlias($serviceId.'.client', new Alias($arguments['service'], false));
324323
}
325324

326325
$container
327326
->register($serviceId, PluginClient::class)
327+
->setPublic($arguments['public'])
328328
->setFactory([new Reference(PluginClientFactory::class), 'createClient'])
329329
->addArgument(new Reference($serviceId.'.client'))
330330
->addArgument(

Tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public function testSupportsAllConfigFormats()
119119
'factory' => 'httplug.factory.guzzle6',
120120
'http_methods_client' => true,
121121
'service' => null,
122+
'public' => false,
122123
'flexible_client' => false,
123124
'batch_client' => false,
124125
'plugins' => [

Tests/Unit/DependencyInjection/HttplugExtensionTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,30 @@ private function verifyProfilingDisabled()
267267
);
268268
}
269269
}
270+
271+
public function testClientShouldBePrivatByDefault()
272+
{
273+
$this->load([
274+
'clients' => [
275+
'acme' => [],
276+
],
277+
]);
278+
279+
$this->assertContainerBuilderHasService('httplug.client.acme');
280+
$this->assertFalse($this->container->getDefinition('httplug.client.acme')->isPublic());
281+
}
282+
283+
public function testClientCanBePublic()
284+
{
285+
$this->load([
286+
'clients' => [
287+
'acme' => [
288+
'public' => true,
289+
],
290+
],
291+
]);
292+
293+
$this->assertContainerBuilderHasService('httplug.client.acme');
294+
$this->assertTrue($this->container->getDefinition('httplug.client.acme')->isPublic());
295+
}
270296
}

0 commit comments

Comments
 (0)