Skip to content

Commit 3aa6c2c

Browse files
committed
Allow injection of extra container definitions
1 parent dcfb052 commit 3aa6c2c

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/Factory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private static function createContainer(LoopInterface $loop, array $options): Co
4343
return CommandBusFactory::create($container);
4444
},
4545
]);
46+
$container->addDefinitions($options[Options::CONTAINER_DEFINITIONS] ?? []);
4647

4748
return $container->build();
4849
}

src/Options.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
class Options
66
{
7-
const HYDRATOR = 'hydrator';
8-
const HYDRATOR_OPTIONS = 'hydrator_options';
9-
const TRANSPORT = 'transport';
10-
const TRANSPORT_OPTIONS = 'transport_options';
7+
const HYDRATOR = 'hydrator';
8+
const HYDRATOR_OPTIONS = 'hydrator_options';
9+
const TRANSPORT = 'transport';
10+
const TRANSPORT_OPTIONS = 'transport_options';
11+
const CONTAINER_DEFINITIONS = 'container_definitions';
1112
}

tests/FactoryTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ public function testCreate()
2121
{
2222
$loop = LoopFactory::create();
2323

24+
$stdClass = new \stdClass();
25+
$stdClass->foo = 'bar';
26+
2427
$client = Factory::create(
2528
$loop,
2629
[
2730
Options::HYDRATOR_OPTIONS => [],
2831
Options::TRANSPORT_OPTIONS => [],
32+
Options::CONTAINER_DEFINITIONS => [
33+
\stdClass::class => $stdClass,
34+
],
2935
]
3036
);
3137

@@ -36,6 +42,9 @@ public function testCreate()
3642
$this->assertSame($loop, $container->get(LoopInterface::class));
3743
$this->assertInstanceOf(Hydrator::class, $container->get(Hydrator::class));
3844
$this->assertInstanceOf(TransportClient::class, $container->get(TransportClient::class));
45+
$this->assertInstanceOf(\stdClass::class, $container->get(\stdClass::class));
46+
$this->assertSame($stdClass, $container->get(\stdClass::class));
47+
$this->assertSame('bar', $container->get(\stdClass::class)->foo);
3948

4049
try {
4150
await($client->handle(new class() {}), $loop);

0 commit comments

Comments
 (0)