Completed
Push — master ( 3633f5...fa8aa1 )
by Rémi
03:57
created

DoctrineEntityManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace RemiSan\TransactionManager\Doctrine;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use RemiSan\TransactionManager\Exception\BeginException;
7
use RemiSan\TransactionManager\Exception\CommitException;
8
use RemiSan\TransactionManager\Exception\RollbackException;
9
use RemiSan\TransactionManager\Transactional;
10
11
class DoctrineEntityManager implements Transactional
12
{
13
    /**
14
     * @var EntityManagerInterface
15
     */
16
    private $entityManager;
17
18
    /**
19
     * Constructor.
20
     *
21
     * @param EntityManagerInterface $entityManager
22
     */
23
    public function __construct(EntityManagerInterface $entityManager)
24
    {
25
        $this->entityManager = $entityManager;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function beginTransaction()
32
    {
33
        try {
34
            $this->entityManager->beginTransaction();
35
        } catch (\Exception $e) {
36
            throw new BeginException('Cannot begin Doctrine ORM transaction', $e->getCode(), $e);
37
        }
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function commit()
44
    {
45
        try {
46
            $this->entityManager->commit();
47
        } catch (\Exception $e) {
48
            throw new CommitException('Cannot commit Doctrine ORM transaction', $e->getCode(), $e);
49
        }
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function rollback()
56
    {
57
        try {
58
            $this->entityManager->rollback();
59
        } catch (\Exception $e) {
60
            throw new RollbackException('Cannot rollback Doctrine ORM transaction', $e->getCode(), $e);
61
        }
62
    }
63
}
64