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 | * Set current depth. |
||
70 | * |
||
71 | * @param int $newDepth |
||
72 | * The new depth. |
||
73 | * |
||
74 | * @return int |
||
75 | * The old depth. |
||
76 | */ |
||
77 | 3 | public function setDepth($newDepth) |
|
86 | |||
87 | /** |
||
88 | * Remove save points to and acquire index of latest active savepoint. |
||
89 | * |
||
90 | * @param int $oldDepth |
||
91 | * The old depth. |
||
92 | * @param int $newDepth |
||
93 | * The new depth. |
||
94 | * |
||
95 | * @return int |
||
96 | * The index of the last open save point. |
||
97 | */ |
||
98 | 2 | protected function closeSavePoints($oldDepth, $newDepth) |
|
109 | |||
110 | /** |
||
111 | * Collection operations from the specified index. |
||
112 | * |
||
113 | * @param int $idx |
||
114 | * The starting index. |
||
115 | * |
||
116 | * @return Operation[] |
||
117 | * The operations from the specified index (included) |
||
118 | */ |
||
119 | 2 | protected function collectOperations($idx) |
|
133 | |||
134 | /** |
||
135 | * Run commit on operations and remove them from the buffer. |
||
136 | * |
||
137 | * @param Operation[] $operations |
||
138 | * The operations to commit. |
||
139 | */ |
||
140 | 1 | protected function commitOperations($operations) |
|
147 | |||
148 | /** |
||
149 | * Run commit on operations and remove them from the buffer. |
||
150 | * |
||
151 | * @param Operation[] $operations |
||
152 | * The operations to commit. |
||
153 | */ |
||
154 | 1 | protected function rollbackOperations($operations) |
|
161 | |||
162 | /** |
||
163 | * Start transaction. |
||
164 | * |
||
165 | * @param int $newDepth |
||
166 | * (optional) If specified, use as new depth, otherwise increment current depth. |
||
167 | * |
||
168 | */ |
||
169 | 1 | public function startTransaction($newDepth = null) |
|
174 | |||
175 | /** |
||
176 | * Commit transaction. |
||
177 | * |
||
178 | * @param int $newDepth |
||
179 | * (optional) If specified, use as new depth, otherwise decrement current depth. |
||
180 | * |
||
181 | */ |
||
182 | 2 | public function commitTransaction($newDepth = null) |
|
195 | |||
196 | /** |
||
197 | * Rollback transaction. |
||
198 | * |
||
199 | * @param int $newDepth |
||
200 | * (optional) If specified, use as new depth, otherwise decrement current depth. |
||
201 | * |
||
202 | */ |
||
203 | 2 | public function rollbackTransaction($newDepth = null) |
|
212 | |||
213 | /** |
||
214 | * Add operation. |
||
215 | * |
||
216 | * @param Operation $operation |
||
217 | * The operation to add to the connection. |
||
218 | * |
||
219 | * @return Operation |
||
220 | * The operation added. |
||
221 | */ |
||
222 | 1 | public function addOperation(Operation $operation) |
|
234 | |||
235 | /** |
||
236 | * Check if the connection has an operation. |
||
237 | * |
||
238 | * @param Operation $operation |
||
239 | * The operation to check for. |
||
240 | * |
||
241 | * @return bool |
||
242 | * TRUE if the operation exists. |
||
243 | */ |
||
244 | 2 | public function hasOperation(Operation $operation) |
|
248 | |||
249 | /** |
||
250 | * Remove operation. |
||
251 | * |
||
252 | * @param Operation $operation |
||
253 | * The operation to remove from the connection. |
||
254 | */ |
||
255 | 1 | public function removeOperation(Operation $operation) |
|
259 | |||
260 | /** |
||
261 | * Short-hand notation for adding code to be run on commit. |
||
262 | * |
||
263 | * @param callable $callback |
||
264 | * The code to run on commit. |
||
265 | * |
||
266 | * @return Operation |
||
267 | * The operation created. |
||
268 | */ |
||
269 | 1 | public function onCommit(callable $callback) |
|
274 | |||
275 | /** |
||
276 | * Short-hand notation for adding code to be run on rollback. |
||
277 | * |
||
278 | * @param callable $callback |
||
279 | * The code to run on rollback. |
||
280 | * |
||
281 | * @return Operation |
||
282 | * The operation created. |
||
283 | */ |
||
284 | 1 | public function onRollback(callable $callback) |
|
289 | |||
290 | /** |
||
291 | * Short-hand notation for adding code to be run on rollback. |
||
292 | * |
||
293 | * @param mixed $value |
||
294 | * The value to add. |
||
295 | * |
||
296 | * @return Operation |
||
297 | * The operation created. |
||
298 | */ |
||
299 | 1 | public function addValue($value) |
|
304 | } |
||
305 |