Skip to content

Commit 1500a79

Browse files
committed
First stab at replacing league/container
1 parent 69e8fc9 commit 1500a79

File tree

3 files changed

+165
-27
lines changed

3 files changed

+165
-27
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"league/container": "^2.2",
2020
"league/event": "^2.1",
2121
"league/tactician-container": "^1.0",
22+
"php-di/php-di": "^5.4",
2223
"wyrihaximus/tactician-command-handler-mapper": "^1.0"
2324
},
2425
"require-dev": {

composer.lock

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

src/Factory.php

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
use ApiClients\Foundation\Transport\Client as TransportClient;
1010
use ApiClients\Foundation\Transport\Factory as TransportFactory;
1111
use ApiClients\Tools\CommandBus\CommandBus;
12+
use DI\ContainerBuilder;
1213
use Generator;
1314
use Interop\Container\ContainerInterface;
1415
use League\Container\Container;
15-
use League\Container\ReflectionContainer;
16-
use League\Event\Emitter;
1716
use League\Event\EmitterInterface;
1817
use League\Tactician\Container\ContainerLocator;
1918
use League\Tactician\Handler\CommandHandlerMiddleware;
@@ -25,37 +24,35 @@ final class Factory
2524
{
2625
public static function create(
2726
LoopInterface $loop = null,
28-
ContainerInterface $wrappedContainer = null,
2927
array $options = []
3028
): Client {
31-
$container = self::createContainer($wrappedContainer);
32-
33-
$container->share(EmitterInterface::class, new Emitter());
34-
$container->share(TransportClient::class, self::createTransport($container, $loop, $options));
35-
$container->share(Hydrator::class, self::createHydrator($container, $options));
36-
$container->share(CommandBus::class, function () use ($container) {
37-
return self::createCommandBus($container);
38-
});
39-
40-
foreach (self::locateServices($container->get(EmitterInterface::class)) as $service) {
41-
$container->share($service);
42-
}
43-
4429
return new Client(
45-
$container
30+
self::createContainer($loop, $options)
4631
);
4732
}
4833

49-
private static function createContainer(ContainerInterface $wrappedContainer = null): Container
34+
private static function createContainer(LoopInterface $loop, array $options): Container
5035
{
51-
$container = new Container();
52-
$container->delegate(new ReflectionContainer());
53-
54-
if ($wrappedContainer instanceof ContainerInterface) {
55-
$container->delegate($wrappedContainer);
56-
}
36+
$container = new ContainerBuilder();
37+
38+
$container->addDefinitions([
39+
LoopInterface::class => $loop,
40+
TransportClient::class => function (ContainerInterface $container, LoopInterface $loop) use ($options) {
41+
return self::createTransport($container, $loop, $options);
42+
},
43+
Hydrator::class => function (ContainerInterface $container) use ($options) {
44+
return self::createHydrator($container, $options);
45+
},
46+
CommandBus::class => function (ContainerInterface $container) {
47+
return self::createCommandBus($container);
48+
},
49+
]);
50+
51+
/*foreach (self::locateServices($container->get(EmitterInterface::class)) as $service) {
52+
$container->share($service);
53+
}*/
5754

58-
return $container;
55+
return $container->build();
5956
}
6057

6158
private static function createCommandBus(ContainerInterface $container): CommandBus

0 commit comments

Comments
 (0)