Passed
Push — master ( 23e253...b3bed4 )
by Mr
02:58
created

CommandRouterProvisioner   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 36
ccs 0
cts 31
cp 0
rs 10
c 0
b 0
f 0
wmc 4
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/boot project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Boot\Service\Provisioner;
10
11
use Auryn\Injector;
12
use Daikon\Boot\MessageBus\CommandRouter;
13
use Daikon\Boot\Service\ServiceDefinitionInterface;
14
use Daikon\Config\ConfigProviderInterface;
15
use Daikon\EventSourcing\Aggregate\Command\CommandHandler;
16
use Daikon\EventSourcing\EventStore\UnitOfWorkMap;
17
18
final class CommandRouterProvisioner implements ProvisionerInterface
19
{
20
    public function provision(
21
        Injector $injector,
22
        ConfigProviderInterface $configProvider,
23
        ServiceDefinitionInterface $serviceDefinition
24
    ): void {
25
        $commandConfigs = (array)$configProvider->get('services.daikon.command_router.commands', []);
26
        $injector
27
            ->share(CommandRouter::class)
28
            ->delegate(
29
                CommandRouter::class,
30
                function (UnitOfWorkMap $uowMap) use ($injector, $commandConfigs): CommandRouter {
31
                    $handlerMap = [];
32
                    foreach ($commandConfigs as $uowKey => $registeredHandlers) {
33
                        foreach ($registeredHandlers as $commandFqcn => $handlerFqcn) {
34
                            $handlerMap[$commandFqcn] = fn(): CommandHandler => $injector->make(
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected ':', expecting T_DOUBLE_ARROW on line 34 at column 60
Loading history...
35
                                $handlerFqcn,
36
                                [':unitOfWork' => $uowMap->get($uowKey)]
37
                            );
38
                        }
39
                    }
40
                    return new CommandRouter($handlerMap);
41
                }
42
            );
43
    }
44
}
45