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 | * Get current depth. |
||
60 | * |
||
61 | * @return int |
||
62 | */ |
||
63 | 1 | public function getDepth() |
|
67 | |||
68 | /** |
||
69 | * Remove save points to and acquire index of latest active savepoint. |
||
70 | * |
||
71 | * @param int $oldDepth |
||
72 | * The old depth. |
||
73 | * @param int $newDepth |
||
74 | * The new depth. |
||
75 | * |
||
76 | * @return int |
||
77 | * The index of the last open save point. |
||
78 | */ |
||
79 | 2 | protected function closeSavePoints($oldDepth, $newDepth) |
|
90 | |||
91 | /** |
||
92 | * Collection operations from the specified index. |
||
93 | * |
||
94 | * @param int $idx |
||
95 | * The starting index. |
||
96 | * |
||
97 | * @return Operation[] |
||
98 | * The operations from the specified index (included) |
||
99 | */ |
||
100 | protected function collectOperations($idx) |
||
114 | |||
115 | /** |
||
116 | * Run commit on operations and remove them from the buffer. |
||
117 | * |
||
118 | * @param Operation[] $operations |
||
119 | * The operations to commit. |
||
120 | */ |
||
121 | 1 | protected function commitOperations($operations) |
|
128 | |||
129 | /** |
||
130 | * Run commit on operations and remove them from the buffer. |
||
131 | * |
||
132 | * @param Operation[] $operations |
||
133 | * The operations to commit. |
||
134 | */ |
||
135 | 1 | protected function rollbackOperations($operations) |
|
142 | |||
143 | /** |
||
144 | * Start transaction. |
||
145 | * |
||
146 | * @param int $newDepth |
||
147 | * (optional) If specified, use as new depth, otherwise increment current depth. |
||
148 | * |
||
149 | */ |
||
150 | 1 | public function startTransaction($newDepth = null) |
|
155 | |||
156 | /** |
||
157 | * Commit transaction. |
||
158 | * |
||
159 | * @param int $newDepth |
||
160 | * (optional) If specified, use as new depth, otherwise decrement current depth. |
||
161 | * |
||
162 | */ |
||
163 | 2 | public function commitTransaction($newDepth = null) |
|
180 | |||
181 | /** |
||
182 | * Rollback transaction. |
||
183 | * |
||
184 | * @param int $newDepth |
||
185 | * (optional) If specified, use as new depth, otherwise decrement current depth. |
||
186 | * |
||
187 | */ |
||
188 | 2 | public function rollbackTransaction($newDepth = null) |
|
201 | |||
202 | /** |
||
203 | * Add operation. |
||
204 | * |
||
205 | * @param Operation $operation |
||
206 | * The operation to add to the connection. |
||
207 | * |
||
208 | * @return Operation |
||
209 | * The operation added. |
||
210 | */ |
||
211 | 1 | public function addOperation(Operation $operation) |
|
223 | |||
224 | /** |
||
225 | * Check if the connection has an operation. |
||
226 | * |
||
227 | * @param Operation $operation |
||
228 | * The operation to check for. |
||
229 | * |
||
230 | * @return bool |
||
231 | * TRUE if the operation exists. |
||
232 | */ |
||
233 | 2 | public function hasOperation(Operation $operation) |
|
237 | |||
238 | /** |
||
239 | * Remove operation. |
||
240 | * |
||
241 | * @param Operation $operation |
||
242 | * The operation to remove from the connection. |
||
243 | */ |
||
244 | 1 | public function removeOperation(Operation $operation) |
|
248 | |||
249 | /** |
||
250 | * Short-hand notation for adding code to be run on commit. |
||
251 | * |
||
252 | * @param callable $callback |
||
253 | * The code to run on commit. |
||
254 | * |
||
255 | * @return Operation |
||
256 | * The operation created. |
||
257 | */ |
||
258 | 1 | public function onCommit(callable $callback) |
|
263 | |||
264 | /** |
||
265 | * Short-hand notation for adding code to be run on rollback. |
||
266 | * |
||
267 | * @param callable $callback |
||
268 | * The code to run on rollback. |
||
269 | * |
||
270 | * @return Operation |
||
271 | * The operation created. |
||
272 | */ |
||
273 | 1 | public function onRollback(callable $callback) |
|
278 | |||
279 | /** |
||
280 | * Short-hand notation for adding code to be run on rollback. |
||
281 | * |
||
282 | * @param mixed $value |
||
283 | * The value to add. |
||
284 | * |
||
285 | * @return Operation |
||
286 | * The operation created. |
||
287 | */ |
||
288 | 1 | public function addValue($value) |
|
293 | } |
||
294 |