Total Complexity | 4 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | final class DoctrineSubscriber implements EventSubscriber |
||
15 | { |
||
16 | private TransactionManager $transactionManager; |
||
17 | |||
18 | public function __construct(TransactionManager $transactionManager) |
||
19 | { |
||
20 | $this->transactionManager = $transactionManager; |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * It is called inside EntityManager#flush() after the changes to all the managed entities |
||
25 | * and their associations have been computed. |
||
26 | * |
||
27 | * @see https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#onflush |
||
28 | */ |
||
29 | public function onFlush(OnFlushEventArgs $args): void |
||
30 | { |
||
31 | $entityManager = $args->getObjectManager(); |
||
32 | $transaction = new Transaction($entityManager); |
||
33 | |||
34 | // Populate transaction |
||
35 | $this->transactionManager->populate($transaction); |
||
36 | |||
37 | $driver = $entityManager->getConnection()->getDriver(); |
||
|
|||
38 | if ($driver instanceof DHDriver) { |
||
39 | $driver->addDHFlusher(function () use ($transaction): void { |
||
40 | $this->transactionManager->process($transaction); |
||
41 | $transaction->reset(); |
||
42 | }); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | public function getSubscribedEvents(): array |
||
49 | } |
||
50 | } |
||
51 |