1 | <?php |
||
10 | class Connection |
||
11 | { |
||
12 | /** |
||
13 | * @var Operation[] |
||
14 | */ |
||
15 | protected $operations = []; |
||
16 | |||
17 | /** |
||
18 | * @var int |
||
19 | */ |
||
20 | protected $idx = 0; |
||
21 | |||
22 | /** |
||
23 | * @var int[] |
||
24 | */ |
||
25 | protected $savePoints = []; |
||
26 | |||
27 | /** |
||
28 | * @var int |
||
29 | */ |
||
30 | protected $depth = 0; |
||
31 | |||
32 | /** |
||
33 | * @var null|string |
||
34 | */ |
||
35 | protected $connectionId; |
||
36 | |||
37 | /** |
||
38 | * Connection constructor. |
||
39 | * |
||
40 | * @param null|string $connectionId |
||
41 | * (optional) The id of the connection. |
||
42 | */ |
||
43 | 1 | public function __construct($connectionId = null) |
|
47 | |||
48 | /** |
||
49 | * Get connection id. |
||
50 | * |
||
51 | * @return null|string |
||
52 | */ |
||
53 | 1 | public function connectionId() |
|
57 | |||
58 | /** |
||
59 | * Remove savepoints to and acquire index of latest active savepoint. |
||
60 | * |
||
61 | * @param int $oldDepth |
||
62 | * The old depth. |
||
63 | * @param $newDepth |
||
64 | * The new depth. |
||
65 | * |
||
66 | * @return int|null |
||
67 | * The last index, if found. |
||
68 | */ |
||
69 | 2 | public function closeSavepoints($oldDepth, $newDepth) |
|
70 | { |
||
71 | 2 | $idx = null; |
|
72 | 2 | for ($depth = $newDepth + 1; $depth <= $oldDepth; $depth++) { |
|
73 | 2 | if (isset($this->savePoints[$depth])) { |
|
74 | 2 | $idx = isset($idx) ? $idx : $this->savePoints[$depth]; |
|
75 | 2 | unset($this->savePoints[$depth]); |
|
76 | 2 | } |
|
77 | 2 | } |
|
78 | 2 | return $idx; |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | 1 | public function startTransaction($newDepth = null) |
|
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | 2 | public function commitTransaction($newDepth = null) |
|
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | 2 | public function rollbackTransaction($newDepth = null) |
|
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | 1 | public function addOperation(Operation $operation) |
|
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | 2 | public function hasOperation(Operation $operation) |
|
172 | |||
173 | /** |
||
174 | * {@inheritdoc} |
||
175 | */ |
||
176 | 1 | public function removeOperation(Operation $operation) |
|
180 | |||
181 | /** |
||
182 | * Short-hand notation for adding code to be run on commit. |
||
183 | * |
||
184 | * @param callable $callback |
||
185 | * The code to run on commit. |
||
186 | * |
||
187 | * @return Operation |
||
188 | */ |
||
189 | 1 | public function onCommit(callable $callback) |
|
194 | |||
195 | /** |
||
196 | * Short-hand notation for adding code to be run on rollback. |
||
197 | * |
||
198 | * @param callable $callback |
||
199 | * The code to run on rollback. |
||
200 | * |
||
201 | * @return Operation |
||
202 | */ |
||
203 | 1 | public function onRollback(callable $callback) |
|
208 | |||
209 | /** |
||
210 | * Short-hand notation for adding code to be run on rollback. |
||
211 | * |
||
212 | * @param mixed $value |
||
213 | * The value to add. |
||
214 | * |
||
215 | * @return Operation |
||
216 | */ |
||
217 | 1 | public function addValue($value) |
|
222 | } |
||
223 |