1 | <?php |
||
13 | trait HandlesMultipleEntityManagers |
||
14 | { |
||
15 | /** |
||
16 | * @var ManagerRegistry |
||
17 | */ |
||
18 | protected $managerRegistry; |
||
19 | |||
20 | /** |
||
21 | * @param ManagerRegistry $managerRegistry |
||
22 | */ |
||
23 | 5 | protected function setManagerRegistry(ManagerRegistry $managerRegistry): void |
|
27 | |||
28 | /** |
||
29 | * @param string[] $names |
||
30 | * @throws RollbackException |
||
31 | */ |
||
32 | 4 | public function flushManagersAtomically(array $names): void |
|
33 | { |
||
34 | 4 | $this->beginTransactions($names); |
|
35 | try { |
||
36 | try { |
||
37 | 4 | $this->flush($names); |
|
38 | 3 | $this->commit($names); |
|
39 | 2 | return; |
|
40 | 2 | } catch (Throwable $e) { |
|
41 | 2 | $this->rollback($names); |
|
42 | 1 | throw new RollbackException($e); |
|
43 | } |
||
44 | 2 | } catch (ConnectionException $e) { |
|
45 | 1 | throw new RollbackFailedException($e); |
|
46 | } |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @throws RollbackException |
||
51 | */ |
||
52 | 4 | public function flushAllManagersAtomically(): void |
|
56 | |||
57 | /** |
||
58 | * @param string[] $names |
||
59 | */ |
||
60 | 1 | public function clearManagers(array $names): void |
|
66 | |||
67 | /** |
||
68 | * @return void |
||
69 | */ |
||
70 | 1 | public function clearAllManagers(): void |
|
74 | |||
75 | /** |
||
76 | * @param string[] $names |
||
77 | * @throws ORMException |
||
78 | */ |
||
79 | 4 | protected function flush(array $names): void |
|
85 | |||
86 | /** |
||
87 | * @param string[] $names |
||
88 | */ |
||
89 | 4 | protected function beginTransactions(array $names): void |
|
95 | |||
96 | /** |
||
97 | * @param string[] $names |
||
98 | * @throws ConnectionException |
||
99 | */ |
||
100 | 3 | protected function commit(array $names): void |
|
106 | |||
107 | /** |
||
108 | * @param string[] $names |
||
109 | * @throws ConnectionException |
||
110 | */ |
||
111 | 2 | protected function rollback(array $names): void |
|
117 | |||
118 | /** |
||
119 | * @param string $name |
||
120 | * @return EntityManager |
||
121 | */ |
||
122 | 5 | protected function getEntityManager(string $name): EntityManager |
|
126 | |||
127 | /** |
||
128 | * @param string $name |
||
129 | * @return Connection |
||
130 | */ |
||
131 | 4 | protected function getConnection(string $name): Connection |
|
135 | } |
||
136 |