Transaction.php
3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
namespace Phalcon\Mvc\Model {
/**
* Phalcon\Mvc\Model\Transaction
*
* Transactions are protective blocks where SQL statements are only permanent if they can
* all succeed as one atomic action. Phalcon\Transaction is intended to be used with Phalcon_Model_Base.
* Phalcon Transactions should be created using Phalcon\Transaction\Manager.
*
*<code>
*try {
*
* $manager = new Phalcon\Mvc\Model\Transaction\Manager();
*
* $transaction = $manager->get();
*
* $robot = new Robots();
* $robot->setTransaction($transaction);
* $robot->name = 'WALL·E';
* $robot->created_at = date('Y-m-d');
* if ($robot->save() == false) {
* $transaction->rollback("Can't save robot");
* }
*
* $robotPart = new RobotParts();
* $robotPart->setTransaction($transaction);
* $robotPart->type = 'head';
* if ($robotPart->save() == false) {
* $transaction->rollback("Can't save robot part");
* }
*
* $transaction->commit();
*
*} catch(Phalcon\Mvc\Model\Transaction\Failed $e) {
* echo 'Failed, reason: ', $e->getMessage();
*}
*
*</code>
*/
class Transaction implements \Phalcon\Mvc\Model\TransactionInterface {
protected $_connection;
protected $_activeTransaction;
protected $_isNewTransaction;
protected $_rollbackOnAbort;
protected $_manager;
protected $_messages;
protected $_rollbackRecord;
/**
* \Phalcon\Mvc\Model\Transaction constructor
*
* @param \Phalcon\DiInterface $dependencyInjector
* @param boolean $autoBegin
* @param string $service
*/
public function __construct($dependencyInjector, $autoBegin=null, $service=null){ }
/**
* Sets transaction manager related to the transaction
*
* @param \Phalcon\Mvc\Model\Transaction\ManagerInterface $manager
*/
public function setTransactionManager($manager){ }
/**
* Starts the transaction
*
* @return boolean
*/
public function begin(){ }
/**
* Commits the transaction
*
* @return boolean
*/
public function commit(){ }
/**
* Rollbacks the transaction
*
* @param string $rollbackMessage
* @param \Phalcon\Mvc\ModelInterface $rollbackRecord
* @return boolean
*/
public function rollback($rollbackMessage=null, $rollbackRecord=null){ }
/**
* Returns the connection related to transaction
*
* @return \Phalcon\Db\AdapterInterface
*/
public function getConnection(){ }
/**
* Sets if is a reused transaction or new once
*
* @param boolean $isNew
*/
public function setIsNewTransaction($isNew){ }
/**
* Sets flag to rollback on abort the HTTP connection
*
* @param boolean $rollbackOnAbort
*/
public function setRollbackOnAbort($rollbackOnAbort){ }
/**
* Checks whether transaction is managed by a transaction manager
*
* @return boolean
*/
public function isManaged(){ }
/**
* Returns validations messages from last save try
*
* @return array
*/
public function getMessages(){ }
/**
* Checks whether internal connection is under an active transaction
*
* @return boolean
*/
public function isValid(){ }
/**
* Sets object which generates rollback action
*
* @param \Phalcon\Mvc\ModelInterface $record
*/
public function setRollbackedRecord($record){ }
}
}