ORMTransaction::contains()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Isolate\PersistenceContext\Transaction\Doctrine;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Isolate\PersistenceContext\Transaction;
7
8
final class ORMTransaction implements Transaction
9
{
10
    /**
11
     * @var EntityManagerInterface
12
     */
13
    private $entityManager;
14
15
    /**
16
     * @param EntityManagerInterface $entityManager
17
     */
18
    public function __construct(EntityManagerInterface $entityManager)
19
    {
20
        $this->entityManager = $entityManager;
21
        $this->entityManager->beginTransaction();
22
    }
23
24
    /**
25
     * @return void
26
     */
27
    public function commit()
28
    {
29
        $this->entityManager->flush();
30
        $this->entityManager->getConnection()->commit();
31
    }
32
33
    /**
34
     * @return void
35
     */
36
    public function rollback()
37
    {
38
        $this->entityManager->rollback();
39
    }
40
41
    /**
42
     * @param mixed $entity
43
     * @return boolean
44
     */
45
    public function contains($entity)
46
    {
47
        return $this->entityManager->contains($entity);
48
    }
49
50
    /**
51
     * @param mixed $entity
52
     */
53
    public function persist($entity)
54
    {
55
        $this->entityManager->persist($entity);
56
    }
57
58
    /**
59
     * @param mixed $entity
60
     */
61
    public function delete($entity)
62
    {
63
        $this->entityManager->remove($entity);
64
    }
65
}
66