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