Conditions | 8 |
Paths | 7 |
Total Lines | 30 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 8 |
Changes | 0 |
1 | <?php |
||
59 | 4 | public function postFlush(PostFlushEventArgs $args) |
|
60 | { |
||
61 | 4 | $em = $args->getEntityManager(); |
|
62 | |||
63 | 4 | if ($em->isOpen()) { |
|
64 | 3 | $map = $em->getUnitOfWork()->getIdentityMap(); |
|
65 | 3 | $has_events = false; |
|
66 | |||
67 | 3 | foreach ($map as $entities) { |
|
68 | 2 | foreach ($entities as $entity) { |
|
69 | // ignore Doctrine proxy classes |
||
70 | // proxy class can't have a domain events |
||
71 | 2 | if ($entity instanceof Proxy || !($entity instanceof AggregateEvents)) { |
|
72 | 1 | break; |
|
73 | } |
||
74 | |||
75 | 2 | foreach ($entity->pullEvents() as $event) { |
|
76 | 1 | $this->bus->publish($event); |
|
77 | 2 | $has_events = true; |
|
78 | } |
||
79 | } |
||
80 | } |
||
81 | |||
82 | // flush only if has domain events |
||
83 | // it necessary for fix recursive handle flush |
||
84 | 3 | if ($has_events) { |
|
85 | 1 | $em->flush(); |
|
86 | } |
||
87 | } |
||
88 | 4 | } |
|
89 | } |
||
90 |