Skip to content

Commit 356b0e3

Browse files
committed
Look for services and share them within the container
1 parent a438009 commit 356b0e3

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"api-clients/command-bus": "dev-master",
1515
"api-clients/events": "dev-master",
1616
"api-clients/hydrator": "dev-master",
17+
"api-clients/service": "dev-master",
1718
"api-clients/transport": "dev-master",
1819
"league/container": "^2.2",
1920
"league/event": "^2.1",

composer.lock

Lines changed: 46 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Factory.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
namespace ApiClients\Foundation;
44

55
use ApiClients\Foundation\Events\CommandLocatorEvent;
6+
use ApiClients\Foundation\Events\ServiceLocatorEvent;
67
use ApiClients\Foundation\Hydrator\Factory as HydratorFactory;
78
use ApiClients\Foundation\Hydrator\Hydrator;
89
use ApiClients\Foundation\Transport\Client as TransportClient;
910
use ApiClients\Foundation\Transport\Factory as TransportFactory;
1011
use ApiClients\Tools\CommandBus\CommandBus;
12+
use Generator;
1113
use Interop\Container\ContainerInterface;
1214
use League\Container\Container;
1315
use League\Container\ReflectionContainer;
@@ -34,6 +36,12 @@ public static function create(
3436
$container->share(CommandBus::class, function () use ($container) {
3537
return self::createCommandBus($container);
3638
});
39+
array_map(
40+
[$container, 'share'],
41+
iterator_to_array(
42+
self::locateServices($container->get(EmitterInterface::class))
43+
)
44+
);
3745

3846
return new Client(
3947
$container
@@ -78,6 +86,11 @@ private static function mapCommandsToHandlers(EmitterInterface $emitter): array
7886
return $emitter->emit(CommandLocatorEvent::create())->getMap();
7987
}
8088

89+
private static function locateServices(EmitterInterface $emitter): Generator
90+
{
91+
return $emitter->emit(ServiceLocatorEvent::create())->getMap();
92+
}
93+
8194
private static function createTransport(
8295
ContainerInterface $container,
8396
LoopInterface $loop = null,

0 commit comments

Comments
 (0)