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 | 2 | 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) |
|
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | 2 | public function rollbackTransaction($newDepth = null) |
|
145 | |||
146 | /** |
||
147 | * {@inheritdoc} |
||
148 | */ |
||
149 | 1 | public function addOperation(Operation $operation) |
|
161 | |||
162 | /** |
||
163 | * {@inheritdoc} |
||
164 | */ |
||
165 | public function hasOperation(Operation $operation) |
||
169 | |||
170 | /** |
||
171 | * {@inheritdoc} |
||
172 | */ |
||
173 | 1 | public function performOperation(Operation $operation) |
|
178 | |||
179 | /** |
||
180 | * {@inheritdoc} |
||
181 | */ |
||
182 | 1 | public function removeOperation(Operation $operation) |
|
186 | |||
187 | /** |
||
188 | * Short-hand notation for adding running code. |
||
189 | * |
||
190 | * @param callable $callback |
||
191 | * The code to run. |
||
192 | * |
||
193 | * @return Operation |
||
194 | */ |
||
195 | 1 | public function call(callable $callback) |
|
200 | } |
||
201 |