|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gember\EventSourcing\Registry\CommandHandler\Reflector; |
|
6
|
|
|
|
|
7
|
|
|
use Gember\EventSourcing\Registry\CommandHandler\CommandHandlerNotRegisteredException; |
|
8
|
|
|
use Gember\EventSourcing\Registry\CommandHandler\CommandHandlerRegistry; |
|
9
|
|
|
use Gember\EventSourcing\Resolver\UseCase\CommandHandlerDefinition; |
|
|
|
|
|
|
10
|
|
|
use Gember\EventSourcing\Resolver\UseCase\UseCaseResolver; |
|
11
|
|
|
use Gember\EventSourcing\UseCase\EventSourcedUseCase; |
|
12
|
|
|
use Gember\EventSourcing\Util\File\Finder\Finder; |
|
13
|
|
|
use Gember\EventSourcing\Util\File\Reflector\Reflector; |
|
14
|
|
|
use Override; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
final class ReflectorCommandHandlerRegistry implements CommandHandlerRegistry |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var array<class-string, array{class-string<EventSourcedUseCase>, CommandHandlerDefinition}> |
|
|
|
|
|
|
20
|
|
|
*/ |
|
21
|
|
|
private array $definitions = []; |
|
22
|
|
|
|
|
23
|
8 |
|
public function __construct( |
|
24
|
|
|
private readonly Finder $finder, |
|
25
|
|
|
private readonly Reflector $reflector, |
|
26
|
|
|
private readonly UseCaseResolver $useCaseResolver, |
|
27
|
|
|
private readonly string $path, |
|
28
|
8 |
|
) {} |
|
29
|
|
|
|
|
30
|
7 |
|
#[Override] |
|
31
|
|
|
public function retrieve(string $commandName): array |
|
32
|
|
|
{ |
|
33
|
7 |
|
$this->initialize(); |
|
34
|
|
|
|
|
35
|
7 |
|
if (!array_key_exists($commandName, $this->definitions)) { |
|
36
|
2 |
|
throw CommandHandlerNotRegisteredException::withCommandName($commandName); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
5 |
|
return $this->definitions[$commandName]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
7 |
|
private function initialize(): void |
|
43
|
|
|
{ |
|
44
|
7 |
|
if ($this->definitions !== []) { |
|
45
|
|
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
7 |
|
$files = $this->finder->getFiles($this->path); |
|
49
|
|
|
|
|
50
|
7 |
|
foreach ($files as $file) { |
|
51
|
6 |
|
if ($file === '') { |
|
52
|
3 |
|
continue; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
6 |
|
$reflectionClass = $this->reflector->reflectClassFromFile($file); |
|
56
|
|
|
|
|
57
|
6 |
|
if (!$reflectionClass->implementsInterface(EventSourcedUseCase::class)) { |
|
58
|
1 |
|
continue; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** @var class-string<EventSourcedUseCase> $useCaseClassName */ |
|
62
|
5 |
|
$useCaseClassName = $reflectionClass->getName(); |
|
63
|
|
|
|
|
64
|
5 |
|
$useCaseDefinition = $this->useCaseResolver->resolve($useCaseClassName); |
|
65
|
|
|
|
|
66
|
5 |
|
foreach ($useCaseDefinition->commandHandlers as $commandHandlerDefinition) { |
|
67
|
5 |
|
$this->definitions[$commandHandlerDefinition->commandClassName] = [ |
|
68
|
5 |
|
$useCaseClassName, |
|
69
|
5 |
|
$commandHandlerDefinition, |
|
70
|
5 |
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths