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