|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Game\Features\Player; |
|
6
|
|
|
|
|
7
|
|
|
use Countable; |
|
8
|
|
|
use Doctrine\Common\EventSubscriber; |
|
|
|
|
|
|
9
|
|
|
use Doctrine\ORM\Event\LifecycleEventArgs; |
|
|
|
|
|
|
10
|
|
|
use Doctrine\ORM\Event\PostFlushEventArgs; |
|
|
|
|
|
|
11
|
|
|
use Doctrine\ORM\Events; |
|
|
|
|
|
|
12
|
|
|
use Symfony\Component\Messenger\MessageBusInterface; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
final class DomainEventsSubscriber implements EventSubscriber, Countable |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var DomainEventInterface[] |
|
18
|
|
|
*/ |
|
19
|
|
|
private array $events = []; |
|
20
|
|
|
private MessageBusInterface $messageBus; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct(MessageBusInterface $messageBus) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->messageBus = $messageBus; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function count(): int |
|
28
|
|
|
{ |
|
29
|
|
|
return count($this->events); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getSubscribedEvents(): array |
|
33
|
|
|
{ |
|
34
|
|
|
return [ |
|
35
|
|
|
Events::postPersist, |
|
36
|
|
|
Events::postUpdate, |
|
37
|
|
|
Events::postRemove, |
|
38
|
|
|
Events::postFlush, |
|
39
|
|
|
]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function postUpdate(LifecycleEventArgs $event): void |
|
43
|
|
|
{ |
|
44
|
|
|
$this->doCollect($event); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function postPersist(LifecycleEventArgs $event): void |
|
48
|
|
|
{ |
|
49
|
|
|
$this->doCollect($event); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function postRemove(LifecycleEventArgs $event): void |
|
53
|
|
|
{ |
|
54
|
|
|
$this->doCollect($event); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function postFlush(PostFlushEventArgs $args): void |
|
58
|
|
|
{ |
|
59
|
|
|
$this->dispatchCollectedEvents(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
private function doCollect(LifecycleEventArgs $event): void |
|
63
|
|
|
{ |
|
64
|
|
|
$entity = $event->getEntity(); |
|
65
|
|
|
if (!$entity instanceof RaiseEventsInterface) { |
|
66
|
|
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
foreach ($entity->popEvents() as $item) { |
|
70
|
|
|
$this->events[spl_object_hash($item)] = $item; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
private function dispatchCollectedEvents(): void |
|
75
|
|
|
{ |
|
76
|
|
|
$events = $this->events; |
|
77
|
|
|
$this->events = []; |
|
78
|
|
|
|
|
79
|
|
|
foreach ($events as $event) { |
|
80
|
|
|
$this->messageBus->dispatch($event); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$this->count() && $this->dispatchCollectedEvents(); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
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