1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gember\EventSourcing\Registry\Saga\Reflector; |
6
|
|
|
|
7
|
|
|
use Gember\EventSourcing\Registry\Saga\SagaNotRegisteredException; |
8
|
|
|
use Gember\EventSourcing\Registry\Saga\SagaRegistry; |
9
|
|
|
use Gember\EventSourcing\Resolver\Saga\Default\EventSubscriber\SagaEventSubscriberResolver; |
10
|
|
|
use Gember\EventSourcing\Resolver\Saga\SagaDefinition; |
|
|
|
|
11
|
|
|
use Gember\EventSourcing\Resolver\Saga\SagaResolver; |
12
|
|
|
use Gember\EventSourcing\Util\File\Finder\Finder; |
13
|
|
|
use Gember\EventSourcing\Util\File\Reflector\Reflector; |
14
|
|
|
use Override; |
|
|
|
|
15
|
|
|
|
16
|
|
|
final class ReflectorSagaRegistry implements SagaRegistry |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var array<string, list<SagaDefinition>> |
|
|
|
|
20
|
|
|
*/ |
21
|
|
|
private array $definitions = []; |
22
|
|
|
|
23
|
6 |
|
public function __construct( |
24
|
|
|
private readonly Finder $finder, |
25
|
|
|
private readonly Reflector $reflector, |
26
|
|
|
private readonly SagaResolver $sagaResolver, |
27
|
|
|
private readonly SagaEventSubscriberResolver $sagaEventSubscriberResolver, |
28
|
|
|
private readonly string $path, |
29
|
6 |
|
) {} |
30
|
|
|
|
31
|
5 |
|
#[Override] |
32
|
|
|
public function retrieve(string $sagaIdName): array |
33
|
|
|
{ |
34
|
5 |
|
$this->initialize(); |
35
|
|
|
|
36
|
5 |
|
if (!array_key_exists($sagaIdName, $this->definitions)) { |
37
|
1 |
|
throw SagaNotRegisteredException::withSagaIdName($sagaIdName); |
38
|
|
|
} |
39
|
|
|
|
40
|
4 |
|
return $this->definitions[$sagaIdName]; |
41
|
|
|
} |
42
|
|
|
|
43
|
5 |
|
private function initialize(): void |
44
|
|
|
{ |
45
|
5 |
|
if ($this->definitions !== []) { |
46
|
|
|
return; |
47
|
|
|
} |
48
|
|
|
|
49
|
5 |
|
$files = $this->finder->getFiles($this->path); |
50
|
|
|
|
51
|
5 |
|
foreach ($files as $file) { |
52
|
5 |
|
if ($file === '') { |
53
|
|
|
continue; |
54
|
|
|
} |
55
|
|
|
|
56
|
5 |
|
$reflectionClass = $this->reflector->reflectClassFromFile($file); |
57
|
|
|
|
58
|
|
|
// A saga must have subscribers |
59
|
5 |
|
$subscribers = $this->sagaEventSubscriberResolver->resolve($reflectionClass->getName()); |
60
|
|
|
|
61
|
5 |
|
if ($subscribers === []) { |
62
|
5 |
|
continue; |
63
|
|
|
} |
64
|
|
|
|
65
|
5 |
|
$definition = $this->sagaResolver->resolve($reflectionClass->getName()); |
66
|
|
|
|
67
|
5 |
|
$this->definitions[$definition->sagaId->sagaIdName][] = $definition; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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