1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gember\EventSourcing\Registry\Reflector; |
6
|
|
|
|
7
|
|
|
use Gember\EventSourcing\Registry\EventNotRegisteredException; |
8
|
|
|
use Gember\EventSourcing\Registry\EventRegistry; |
9
|
|
|
use Gember\EventSourcing\Resolver\DomainEvent\NormalizedEventName\NormalizedEventNameResolver; |
10
|
|
|
use Gember\EventSourcing\Resolver\DomainEvent\NormalizedEventName\UnresolvableEventNameException; |
11
|
|
|
use Gember\EventSourcing\Util\File\Finder\Finder; |
12
|
|
|
use Gember\EventSourcing\Util\File\Reflector\ReflectionFailedException; |
13
|
|
|
use Gember\EventSourcing\Util\File\Reflector\Reflector; |
14
|
|
|
use Override; |
|
|
|
|
15
|
|
|
|
16
|
|
|
final class ReflectorEventRegistry implements EventRegistry |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var array<string, class-string> |
|
|
|
|
20
|
|
|
*/ |
21
|
|
|
private array $events = []; |
22
|
|
|
|
23
|
4 |
|
public function __construct( |
24
|
|
|
private readonly Finder $finder, |
25
|
|
|
private readonly Reflector $reflector, |
26
|
|
|
private readonly NormalizedEventNameResolver $eventNameResolver, |
27
|
|
|
private readonly string $path, |
28
|
4 |
|
) {} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @throws EventNotRegisteredException |
32
|
|
|
* @throws ReflectionFailedException |
33
|
|
|
* @throws UnresolvableEventNameException |
34
|
|
|
*/ |
35
|
3 |
|
#[Override] |
36
|
|
|
public function retrieve(string $eventName): string |
37
|
|
|
{ |
38
|
3 |
|
$this->initialize(); |
39
|
|
|
|
40
|
3 |
|
if (!array_key_exists($eventName, $this->events)) { |
41
|
1 |
|
throw EventNotRegisteredException::withEventName($eventName); |
42
|
|
|
} |
43
|
|
|
|
44
|
2 |
|
return $this->events[$eventName]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @throws ReflectionFailedException |
49
|
|
|
* @throws UnresolvableEventNameException |
50
|
|
|
*/ |
51
|
3 |
|
private function initialize(): void |
52
|
|
|
{ |
53
|
3 |
|
if ($this->events !== []) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
3 |
|
$files = $this->finder->getFiles($this->path); |
58
|
|
|
|
59
|
3 |
|
foreach ($files as $file) { |
60
|
2 |
|
if ($file === '') { |
61
|
2 |
|
continue; |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
|
$reflectionClass = $this->reflector->reflectClassFromFile($file); |
65
|
|
|
|
66
|
2 |
|
$eventName = $this->eventNameResolver->resolve($reflectionClass->getName()); |
67
|
|
|
|
68
|
2 |
|
$this->events[$eventName] = $reflectionClass->getName(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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