|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Antidot\Tactician\Container; |
|
4
|
|
|
|
|
5
|
|
|
use Antidot\Tactician\Container\Config\CommandBusConfig; |
|
6
|
|
|
use Antidot\Tactician\QueryBus; |
|
7
|
|
|
use League\Tactician\CommandBus; |
|
8
|
|
|
use League\Tactician\Handler\CommandHandlerMiddleware; |
|
9
|
|
|
use League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor; |
|
10
|
|
|
use League\Tactician\Handler\Locator\HandlerLocator; |
|
11
|
|
|
use League\Tactician\Handler\MethodNameInflector\MethodNameInflector; |
|
12
|
|
|
use Psr\Container\ContainerInterface; |
|
13
|
|
|
|
|
14
|
|
|
class QueryBusFactory |
|
15
|
|
|
{ |
|
16
|
1 |
|
public function __invoke(ContainerInterface $container): QueryBus |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var array<string, array> $globalConfig */ |
|
19
|
1 |
|
$globalConfig = $container->get('config'); |
|
20
|
1 |
|
$config = CommandBusConfig::createFromArrayConfig($globalConfig['query_bus']); |
|
21
|
|
|
|
|
22
|
|
|
/** @psalm-suppress MixedArgumentTypeCoercion */ |
|
23
|
1 |
|
return new QueryBus(new CommandBus(array_merge( |
|
24
|
1 |
|
array_map(static function (string $middleware) use ($container) { |
|
25
|
1 |
|
return $container->get($middleware); |
|
26
|
1 |
|
}, $config->getMiddleware()), |
|
27
|
|
|
[ |
|
28
|
1 |
|
new CommandHandlerMiddleware( |
|
29
|
|
|
/** @var CommandNameExtractor $nameExtractor */ |
|
30
|
1 |
|
$nameExtractor = $container->get($config->getExtractor()), |
|
31
|
|
|
/** @var HandlerLocator $locator */ |
|
32
|
1 |
|
$locator = $container->get($config->getLocator()), |
|
33
|
|
|
/** @var MethodNameInflector $inflector */ |
|
34
|
1 |
|
$inflector = $container->get($config->getInflector()) |
|
35
|
|
|
), |
|
36
|
|
|
] |
|
37
|
|
|
))); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|