1 | <?php |
||
10 | class Operation |
||
11 | { |
||
12 | /** |
||
13 | * The index in the buffer, keyed by connection id. |
||
14 | * |
||
15 | * @var int[] |
||
16 | */ |
||
17 | protected $idx; |
||
18 | |||
19 | /** |
||
20 | * Callback for commit. |
||
21 | * |
||
22 | * @var callable[] |
||
23 | */ |
||
24 | protected $commit = []; |
||
25 | |||
26 | /** |
||
27 | * Callback for rollback. |
||
28 | * |
||
29 | * @var callable[] |
||
30 | */ |
||
31 | protected $rollback = []; |
||
32 | |||
33 | /** |
||
34 | * Callback for buffer. |
||
35 | * |
||
36 | * @var callable[] |
||
37 | */ |
||
38 | protected $buffer = []; |
||
39 | |||
40 | /** |
||
41 | * Callback for remove. |
||
42 | * |
||
43 | * @var callable[] |
||
44 | */ |
||
45 | protected $remove = []; |
||
46 | |||
47 | /** |
||
48 | * Metadata for operation. |
||
49 | * |
||
50 | * @var mixed[] |
||
51 | */ |
||
52 | protected $metadata = []; |
||
53 | |||
54 | /** |
||
55 | * Result of callback execution. |
||
56 | * |
||
57 | * @var mixed |
||
58 | */ |
||
59 | protected $result; |
||
60 | |||
61 | /** |
||
62 | * Set commit callback. |
||
63 | * |
||
64 | * @param callable $callback |
||
65 | * The callback when this operation is committed. |
||
66 | * |
||
67 | * @return $this |
||
68 | */ |
||
69 | 1 | public function onCommit(callable $callback) |
|
74 | |||
75 | /** |
||
76 | * Set rollback callback. |
||
77 | * |
||
78 | * @param callable $callback |
||
79 | * The callback when this operation is rolled back. |
||
80 | * |
||
81 | * @return $this |
||
82 | */ |
||
83 | 1 | public function onRollback(callable $callback) |
|
88 | |||
89 | /** |
||
90 | * Set rollback callback. |
||
91 | * |
||
92 | * @param callable $callback |
||
93 | * The callback when this operation is rolled back. |
||
94 | * |
||
95 | * @return $this |
||
96 | */ |
||
97 | 1 | public function onRemove(callable $callback) |
|
102 | |||
103 | /** |
||
104 | * Set buffer callback. |
||
105 | * |
||
106 | * @param callable $callback |
||
107 | * The callback when this operation is buffered. |
||
108 | * |
||
109 | * @return $this |
||
110 | */ |
||
111 | 1 | public function onBuffer(callable $callback) |
|
116 | |||
117 | /** |
||
118 | * Get commit callbacks. |
||
119 | * |
||
120 | * @return callable|null |
||
121 | */ |
||
122 | 1 | public function getCommitCallbacks() |
|
126 | |||
127 | /** |
||
128 | * Get rollback callbacks. |
||
129 | * |
||
130 | * @return callable|null |
||
131 | */ |
||
132 | 1 | public function getRollbackCallbacks() |
|
136 | |||
137 | /** |
||
138 | * Get buffer callbacks. |
||
139 | * |
||
140 | * @return callable|null |
||
141 | */ |
||
142 | 1 | public function getBufferCallbacks() |
|
146 | |||
147 | /** |
||
148 | * Get remove callbacks. |
||
149 | * |
||
150 | * @return callable|null |
||
151 | */ |
||
152 | 1 | public function getRemoveCallbacks() |
|
156 | |||
157 | /** |
||
158 | * Set metadata. |
||
159 | * |
||
160 | * @param string $key |
||
161 | * The key of the metadata. |
||
162 | * @param mixed $value |
||
163 | * The value to set. |
||
164 | * |
||
165 | * @return $this |
||
166 | */ |
||
167 | 1 | public function setMetadata($key, $value) |
|
172 | |||
173 | /** |
||
174 | * Get metadata. |
||
175 | * |
||
176 | * @param $key |
||
177 | * The key of the metadata to get. |
||
178 | * |
||
179 | * @return mixed|null |
||
180 | */ |
||
181 | 1 | public function getMetadata($key) |
|
185 | |||
186 | /** |
||
187 | * Get result from callback. |
||
188 | * |
||
189 | * @return mixed |
||
190 | */ |
||
191 | 4 | public function getResult() |
|
195 | |||
196 | /** |
||
197 | * @param Connection $connection |
||
198 | * The connection to use for this id. |
||
199 | * @param string $idx |
||
200 | * The id. |
||
201 | * |
||
202 | * @return $this |
||
203 | */ |
||
204 | 1 | public function setIdx(Connection $connection, $idx) |
|
209 | |||
210 | /** |
||
211 | * Get id. |
||
212 | * |
||
213 | * @param Connection $connection |
||
214 | * The connection to get id from. |
||
215 | * |
||
216 | * @return string|null |
||
217 | */ |
||
218 | 1 | public function idx(Connection $connection) |
|
223 | |||
224 | /** |
||
225 | * Execute commit operation. |
||
226 | * |
||
227 | * @param Connection $connection |
||
228 | * The connection to run this operation on. |
||
229 | * |
||
230 | * @return mixed |
||
231 | */ |
||
232 | 1 | public function commit(Connection $connection = null) |
|
239 | |||
240 | /** |
||
241 | * Execute rollback operation. |
||
242 | * |
||
243 | * @param Connection $connection |
||
244 | * The connection to run this operation on. |
||
245 | * |
||
246 | * @return mixed |
||
247 | */ |
||
248 | 1 | public function rollback(Connection $connection = null) |
|
255 | |||
256 | /** |
||
257 | * Execute buffer operation. |
||
258 | * |
||
259 | * @param Connection $connection |
||
260 | * The connection to run this operation on. |
||
261 | * |
||
262 | * @return mixed |
||
263 | */ |
||
264 | 1 | public function buffer(Connection $connection = null) |
|
271 | |||
272 | /** |
||
273 | * Execute remove operation. |
||
274 | * |
||
275 | * @param Connection $connection |
||
276 | * The connection to run this operation on. |
||
277 | * |
||
278 | * @return mixed |
||
279 | */ |
||
280 | 1 | public function remove(Connection $connection = null) |
|
287 | } |
||
288 |