Skip to content

Commit 83ae982

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

File tree

5 files changed

+128
-3
lines changed

5 files changed

+128
-3
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 to 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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ private function configureClient(ContainerBuilder $container, $clientName, array
325325

326326
$container
327327
->register($serviceId, PluginClient::class)
328+
->setPublic($arguments['public'])
328329
->setFactory([new Reference(PluginClientFactory::class), 'createClient'])
329330
->addArgument(new Reference($serviceId.'.client'))
330331
->addArgument(
@@ -347,7 +348,7 @@ function ($id) {
347348
$container
348349
->register($serviceId.'.flexible', FlexibleHttpClient::class)
349350
->addArgument(new Reference($serviceId.'.flexible.inner'))
350-
->setPublic(false)
351+
->setPublic($arguments['public'])
351352
->setDecoratedService($serviceId)
352353
;
353354
}
@@ -356,7 +357,7 @@ function ($id) {
356357
$container
357358
->register($serviceId.'.http_methods', HttpMethodsClient::class)
358359
->setArguments([new Reference($serviceId.'.http_methods.inner'), new Reference('httplug.message_factory')])
359-
->setPublic(false)
360+
->setPublic($arguments['public'])
360361
->setDecoratedService($serviceId)
361362
;
362363
}
@@ -365,7 +366,7 @@ function ($id) {
365366
$container
366367
->register($serviceId.'.batch_client', BatchClient::class)
367368
->setArguments([new Reference($serviceId.'.batch_client.inner')])
368-
->setPublic(false)
369+
->setPublic($arguments['public'])
369370
->setDecoratedService($serviceId)
370371
;
371372
}

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: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,117 @@ private function verifyProfilingDisabled()
267267
);
268268
}
269269
}
270+
271+
public function testClientShouldBePrivateByDefault()
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 testFlexibleClientShouldBePrivateByDefault()
284+
{
285+
$this->load([
286+
'clients' => [
287+
'acme' => [
288+
'flexible_client' => true,
289+
],
290+
],
291+
]);
292+
293+
$this->assertContainerBuilderHasService('httplug.client.acme');
294+
$this->assertFalse($this->container->getDefinition('httplug.client.acme.flexible')->isPublic());
295+
}
296+
297+
public function testHttpMethodsClientShouldBePrivateByDefault()
298+
{
299+
$this->load([
300+
'clients' => [
301+
'acme' => [
302+
'http_methods_client' => true,
303+
],
304+
],
305+
]);
306+
307+
$this->assertContainerBuilderHasService('httplug.client.acme');
308+
$this->assertFalse($this->container->getDefinition('httplug.client.acme.http_methods')->isPublic());
309+
}
310+
311+
public function testBatchClientShouldBePrivateByDefault()
312+
{
313+
$this->load([
314+
'clients' => [
315+
'acme' => [
316+
'batch_client' => true,
317+
],
318+
],
319+
]);
320+
321+
$this->assertContainerBuilderHasService('httplug.client.acme');
322+
$this->assertFalse($this->container->getDefinition('httplug.client.acme.batch_client')->isPublic());
323+
}
324+
325+
public function testClientCanBePublic()
326+
{
327+
$this->load([
328+
'clients' => [
329+
'acme' => [
330+
'public' => true,
331+
],
332+
],
333+
]);
334+
335+
$this->assertContainerBuilderHasService('httplug.client.acme');
336+
$this->assertTrue($this->container->getDefinition('httplug.client.acme')->isPublic());
337+
}
338+
339+
public function testFlexibleClientCanBePublic()
340+
{
341+
$this->load([
342+
'clients' => [
343+
'acme' => [
344+
'public' => true,
345+
'flexible_client' => true,
346+
],
347+
],
348+
]);
349+
350+
$this->assertContainerBuilderHasService('httplug.client.acme');
351+
$this->assertTrue($this->container->getDefinition('httplug.client.acme.flexible')->isPublic());
352+
}
353+
354+
public function testHttpMethodsClientCanBePublic()
355+
{
356+
$this->load([
357+
'clients' => [
358+
'acme' => [
359+
'public' => true,
360+
'http_methods_client' => true,
361+
],
362+
],
363+
]);
364+
365+
$this->assertContainerBuilderHasService('httplug.client.acme');
366+
$this->assertTrue($this->container->getDefinition('httplug.client.acme.http_methods')->isPublic());
367+
}
368+
369+
public function testBatchClientCanBePublic()
370+
{
371+
$this->load([
372+
'clients' => [
373+
'acme' => [
374+
'public' => true,
375+
'batch_client' => true,
376+
],
377+
],
378+
]);
379+
380+
$this->assertContainerBuilderHasService('httplug.client.acme');
381+
$this->assertTrue($this->container->getDefinition('httplug.client.acme.batch_client')->isPublic());
382+
}
270383
}

0 commit comments

Comments
 (0)