|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Simple EventStore Manager package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Mauro Cassani<https://github.com/mauretto78> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace SimpleEventStoreManager\Infrastructure\Projector; |
|
12
|
|
|
|
|
13
|
|
|
use SimpleEventStoreManager\Domain\Model\Contracts\EventInterface; |
|
14
|
|
|
use SimpleEventStoreManager\Domain\Model\Contracts\EventStoreRepositoryInterface; |
|
15
|
|
|
use SimpleEventStoreManager\Domain\Model\EventAggregate; |
|
|
|
|
|
|
16
|
|
|
use SimpleEventStoreManager\Domain\Model\AggregateUuid; |
|
17
|
|
|
use SimpleEventStoreManager\Infrastructure\Projector\Exceptions\ProjectorDoesNotExistsException; |
|
18
|
|
|
|
|
19
|
|
|
class ProjectionManager |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var Projector[] |
|
23
|
|
|
*/ |
|
24
|
|
|
private $projectors; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var EventStoreRepositoryInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $repo; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* ProjectionManager constructor. |
|
33
|
|
|
* @param EventStoreRepositoryInterface $repo |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(EventStoreRepositoryInterface $repo) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->repo = $repo; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param Projector $projector |
|
42
|
|
|
*/ |
|
43
|
|
|
public function register(Projector $projector) |
|
44
|
|
|
{ |
|
45
|
|
|
foreach ($projector->subcribedEvents() as $subcribedEvent) { |
|
46
|
|
|
$this->projectors[$subcribedEvent] = $projector; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param EventInterface $event |
|
52
|
|
|
* @throws ProjectorDoesNotExistsException |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
public function project(EventInterface $event) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
if (!isset($this->projectors[get_class($event)])) { |
|
57
|
|
|
throw new ProjectorDoesNotExistsException('No Projector found for event ' . get_class($event) . '.'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$this->projectors[get_class($event)]->handle($event); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param AggregateUuid $uuid |
|
65
|
|
|
*/ |
|
66
|
|
|
public function projectFromAnEventAggregate(AggregateUuid $uuid) |
|
67
|
|
|
{ |
|
68
|
|
|
/** @var EventInterface $event */ |
|
69
|
|
|
foreach ($this->repo->byUuid($uuid, EventStoreRepositoryInterface::RETURN_AS_OBJECT) as $event) { |
|
70
|
|
|
try { |
|
71
|
|
|
$this->project($event); |
|
72
|
|
|
} catch (ProjectorDoesNotExistsException $e) { |
|
73
|
|
|
$this->rollbackAnEventAggregate($uuid); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param EventInterface $event |
|
80
|
|
|
* @throws ProjectorDoesNotExistsException |
|
81
|
|
|
*/ |
|
82
|
|
View Code Duplication |
public function rollback(EventInterface $event) |
|
|
|
|
|
|
83
|
|
|
{ |
|
84
|
|
|
if (!isset($this->projectors[get_class($event)])) { |
|
85
|
|
|
throw new ProjectorDoesNotExistsException('No Projector found for event ' . get_class($event) . '.'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$this->projectors[get_class($event)]->rollback($event); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param AggregateUuid $eventUuid |
|
93
|
|
|
*/ |
|
94
|
|
|
public function rollbackAnEventAggregate(AggregateUuid $eventUuid) |
|
95
|
|
|
{ |
|
96
|
|
|
foreach ($this->repo->byUuid($eventUuid, EventStoreRepositoryInterface::RETURN_AS_OBJECT) as $event) { |
|
97
|
|
|
$this->rollback($event); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
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