1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gember\EventSourcing\Registry\CommandHandler\Reflector; |
6
|
|
|
|
7
|
|
|
use Gember\EventSourcing\Resolver\UseCase\CommandHandlers\CommandHandlerDefinition; |
|
|
|
|
8
|
|
|
use Gember\EventSourcing\Registry\CommandHandler\CommandHandlerNotRegisteredException; |
9
|
|
|
use Gember\EventSourcing\Registry\CommandHandler\CommandHandlerRegistry; |
10
|
|
|
use Gember\EventSourcing\Resolver\UseCase\CommandHandlers\CommandHandlersResolver; |
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, CommandHandlerDefinition> |
|
|
|
|
20
|
|
|
*/ |
21
|
|
|
private array $definitions = []; |
22
|
|
|
|
23
|
7 |
|
public function __construct( |
24
|
|
|
private readonly Finder $finder, |
25
|
|
|
private readonly Reflector $reflector, |
26
|
|
|
private readonly CommandHandlersResolver $commandHandlersResolver, |
27
|
|
|
private readonly string $path, |
28
|
7 |
|
) {} |
29
|
|
|
|
30
|
6 |
|
#[Override] |
31
|
|
|
public function retrieve(string $commandName): CommandHandlerDefinition |
32
|
|
|
{ |
33
|
6 |
|
$this->initialize(); |
34
|
|
|
|
35
|
6 |
|
if (!array_key_exists($commandName, $this->definitions)) { |
36
|
1 |
|
throw CommandHandlerNotRegisteredException::withCommandName($commandName); |
37
|
|
|
} |
38
|
|
|
|
39
|
5 |
|
return $this->definitions[$commandName]; |
40
|
|
|
} |
41
|
|
|
|
42
|
6 |
|
private function initialize(): void |
43
|
|
|
{ |
44
|
6 |
|
if ($this->definitions !== []) { |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
6 |
|
$files = $this->finder->getFiles($this->path); |
49
|
|
|
|
50
|
6 |
|
foreach ($files as $file) { |
51
|
5 |
|
if ($file === '') { |
52
|
2 |
|
continue; |
53
|
|
|
} |
54
|
|
|
|
55
|
5 |
|
$reflectionClass = $this->reflector->reflectClassFromFile($file); |
56
|
|
|
|
57
|
|
|
/** @var class-string<EventSourcedUseCase> $useCaseClassName */ |
58
|
5 |
|
$useCaseClassName = $reflectionClass->getName(); |
59
|
|
|
|
60
|
5 |
|
foreach ($this->commandHandlersResolver->resolve($useCaseClassName) as $definition) { |
61
|
5 |
|
$this->definitions[$definition->commandName] = $definition; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
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