Total Complexity | 4 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
16 | final class OrderedDoctrineEventsRecorder |
||
17 | { |
||
18 | /** @var Aggregator */ |
||
19 | private $eventsAggregator; |
||
20 | |||
21 | 2 | public function __construct(Aggregator $eventAggregator) |
|
22 | { |
||
23 | 2 | $this->eventsAggregator = $eventAggregator; |
|
24 | 2 | } |
|
25 | |||
26 | 2 | public function onFlush(OnFlushEventArgs $eventArgs) : void |
|
27 | { |
||
28 | 2 | $unitOfWork = $eventArgs->getEntityManager() |
|
29 | 2 | ->getUnitOfWork(); |
|
30 | |||
31 | 2 | $events = []; |
|
32 | |||
33 | 2 | foreach (self::getEventAwareEntities($unitOfWork) as $entity) { |
|
34 | 1 | $events += $entity->expelRecordedEvents(); |
|
35 | } |
||
36 | |||
37 | 2 | ksort($events); |
|
38 | |||
39 | 2 | Counter::reset(); |
|
40 | 2 | $this->eventsAggregator->aggregate(...$events); |
|
41 | 2 | } |
|
42 | |||
43 | /** |
||
44 | * @return EventAware[] |
||
45 | */ |
||
46 | 2 | private static function getEventAwareEntities(UnitOfWork $unitOfWork) : array |
|
56 | 2 | }); |
|
57 | } |
||
58 | } |
||
59 |