| 1 | <?php |
||
| 7 | class TransactionManager |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var EntityManagerInterface |
||
| 11 | */ |
||
| 12 | private $entityManager; |
||
| 13 | |||
| 14 | 10 | public function __construct(EntityManagerInterface $entityManager) |
|
| 18 | |||
| 19 | 9 | public function beginTransaction() |
|
| 23 | |||
| 24 | 9 | public function commitTransaction() |
|
| 25 | { |
||
| 26 | 9 | $nestingLevel = $this->entityManager->getConnection()->getTransactionNestingLevel(); |
|
| 27 | 9 | if (1 === $nestingLevel) { |
|
| 28 | 9 | $this->entityManager->flush(); |
|
| 29 | } |
||
| 30 | 9 | $this->entityManager->commit(); |
|
| 31 | 9 | } |
|
| 32 | |||
| 33 | public function rollbackTransaction() |
||
| 37 | |||
| 38 | public function isInTransaction() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param callable $func |
||
| 47 | * |
||
| 48 | * @return mixed |
||
| 49 | */ |
||
| 50 | 9 | public function transactional($func) |
|
| 71 | } |
||
| 72 |