99use ApiClients \Foundation \Transport \Client as TransportClient ;
1010use ApiClients \Foundation \Transport \Factory as TransportFactory ;
1111use ApiClients \Tools \CommandBus \CommandBus ;
12+ use DI \ContainerBuilder ;
1213use Generator ;
1314use Interop \Container \ContainerInterface ;
1415use League \Container \Container ;
15- use League \Container \ReflectionContainer ;
16- use League \Event \Emitter ;
1716use League \Event \EmitterInterface ;
1817use League \Tactician \Container \ContainerLocator ;
1918use 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