File tree 1 file changed +64
-0
lines changed
1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace RemiSan \TransactionManager \Doctrine ;
4
+
5
+ use Doctrine \DBAL \Connection ;
6
+ use Doctrine \DBAL \ConnectionException ;
7
+ use RemiSan \TransactionManager \Exception \BeginException ;
8
+ use RemiSan \TransactionManager \Exception \CommitException ;
9
+ use RemiSan \TransactionManager \Exception \RollbackException ;
10
+ use RemiSan \TransactionManager \Transactional ;
11
+
12
+ final class DoctrineDbalConnectionTransactionManager implements Transactional
13
+ {
14
+ /**
15
+ * @var Connection
16
+ */
17
+ private $ dbalConnection ;
18
+
19
+ /**
20
+ * Constructor.
21
+ *
22
+ * @param Connection $dbalConnection
23
+ */
24
+ public function __construct (Connection $ dbalConnection )
25
+ {
26
+ $ this ->dbalConnection = $ dbalConnection ;
27
+ }
28
+
29
+ /**
30
+ * {@inheritdoc}
31
+ */
32
+ public function beginTransaction ()
33
+ {
34
+ try {
35
+ $ this ->dbalConnection ->beginTransaction ();
36
+ } catch (\Exception $ e ) {
37
+ throw new BeginException ('Cannot begin Doctrine DBAL transaction ' );
38
+ }
39
+ }
40
+
41
+ /**
42
+ * {@inheritdoc}
43
+ */
44
+ public function commit ()
45
+ {
46
+ try {
47
+ $ this ->dbalConnection ->commit ();
48
+ } catch (ConnectionException $ e ) {
49
+ throw new CommitException ('Cannot commit Doctrine DBAL transaction ' );
50
+ }
51
+ }
52
+
53
+ /**
54
+ * {@inheritdoc}
55
+ */
56
+ public function rollback ()
57
+ {
58
+ try {
59
+ $ this ->dbalConnection ->commit ();
60
+ } catch (ConnectionException $ e ) {
61
+ throw new RollbackException ('Cannot rollback Doctrine DBAL transaction ' );
62
+ }
63
+ }
64
+ }
You can’t perform that action at this time.
0 commit comments