getCommandHandlersDefinitions()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 1
1
<?php
2
/******************************************************************************
3
 * Copyright (c) 2016 Constantin Galbenu <[email protected]>             *
4
 ******************************************************************************/
5
6
namespace Gica\Cqrs\Command\CommandValidation;
7
8
9
use Gica\Cqrs\Command;
10
use Gica\Cqrs\Command\CommandValidation;
11
use Gica\Cqrs\Command\ValueObject\CommandHandlerDescriptor;
12
13
abstract class CommandValidatorSubscriberByMap implements CommandValidation\CommandValidatorSubscriber
14
{
15
    /**
16
     * @inheritdoc
17
     */
18 2
    public function getHandlersForCommand(Command $command)
19
    {
20 2
        $definitions = $this->getCommandHandlersDefinitions();
21
22 2
        if (!isset($definitions[get_class($command)])) {
23 1
            return [];
24
        }
25
26 1
        $handlersForCommand = $definitions[get_class($command)];
27
28 1
        $result = [];
29
30 1
        foreach ($handlersForCommand as $commandDefinition) {
31
32 1
            list($aggregateClass, $methodName) = $commandDefinition;
33
34 1
            $result[] = new CommandHandlerDescriptor($aggregateClass, $methodName);
35
        }
36
37 1
        return $result;
38
    }
39
40
    abstract protected function getCommandHandlersDefinitions(): array;
41
}