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

CommandRouterProvisioner::factory()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 14
nc 1
nop 2
dl 0
loc 20
ccs 0
cts 18
cp 0
crap 12
rs 9.7998
c 0
b 0
f 0
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