1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dazzle\Loop; |
4
|
|
|
|
5
|
|
|
use Dazzle\Loop\Flow\FlowController; |
6
|
|
|
use Dazzle\Loop\Model\SelectLoop; |
7
|
|
|
use Dazzle\Loop\Timer\TimerInterface; |
8
|
|
|
|
9
|
|
|
class Loop implements LoopExtendedInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var LoopModelInterface |
13
|
|
|
*/ |
14
|
|
|
protected $loop; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param LoopModelInterface |
18
|
|
|
*/ |
19
|
65 |
|
public function __construct(LoopModelInterface $loop = null) |
20
|
|
|
{ |
21
|
65 |
|
$this->loop = $loop === null ? new SelectLoop() : $loop; |
22
|
65 |
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
37 |
|
public function __destruct() |
28
|
|
|
{ |
29
|
|
|
// unset($this->loop); |
|
|
|
|
30
|
37 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @override |
34
|
|
|
* @inheritDoc |
35
|
|
|
*/ |
36
|
10 |
|
public function getModel() |
37
|
|
|
{ |
38
|
10 |
|
return $this->loop; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @override |
43
|
|
|
* @inheritDoc |
44
|
|
|
*/ |
45
|
5 |
|
public function erase($all = false) |
46
|
|
|
{ |
47
|
5 |
|
$this->loop->erase($all); |
48
|
|
|
|
49
|
5 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @override |
54
|
|
|
* @inheritDoc |
55
|
|
|
*/ |
56
|
3 |
|
public function export(LoopExtendedInterface $loop, $all = false) |
57
|
|
|
{ |
58
|
3 |
|
$this->loop->export($loop->getModel(), $all); |
59
|
|
|
|
60
|
3 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @override |
65
|
|
|
* @inheritDoc |
66
|
|
|
*/ |
67
|
3 |
|
public function import(LoopExtendedInterface $loop, $all = false) |
68
|
|
|
{ |
69
|
3 |
|
$this->loop->import($loop->getModel(), $all); |
70
|
|
|
|
71
|
3 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @override |
76
|
|
|
* @inheritDoc |
77
|
|
|
*/ |
78
|
3 |
|
public function swap(LoopExtendedInterface $loop, $all = false) |
79
|
|
|
{ |
80
|
3 |
|
$this->loop->swap($loop->getModel(), $all); |
81
|
|
|
|
82
|
3 |
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @override |
87
|
|
|
* @inheritDoc |
88
|
|
|
*/ |
89
|
2 |
|
public function isRunning() |
90
|
|
|
{ |
91
|
2 |
|
return $this->loop->isRunning(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @override |
96
|
|
|
* @inheritDoc |
97
|
|
|
*/ |
98
|
8 |
|
public function addReadStream($stream, callable $listener) |
99
|
|
|
{ |
100
|
8 |
|
$this->loop->addReadStream($stream, $listener); |
101
|
8 |
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @override |
105
|
|
|
* @inheritDoc |
106
|
|
|
*/ |
107
|
8 |
|
public function addWriteStream($stream, callable $listener) |
108
|
|
|
{ |
109
|
8 |
|
$this->loop->addWriteStream($stream, $listener); |
110
|
8 |
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @override |
114
|
|
|
* @inheritDoc |
115
|
|
|
*/ |
116
|
3 |
|
public function removeReadStream($stream) |
117
|
|
|
{ |
118
|
3 |
|
$this->loop->removeReadStream($stream); |
119
|
3 |
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @override |
123
|
|
|
* @inheritDoc |
124
|
|
|
*/ |
125
|
5 |
|
public function removeWriteStream($stream) |
126
|
|
|
{ |
127
|
5 |
|
$this->loop->removeWriteStream($stream); |
128
|
5 |
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @override |
132
|
|
|
* @inheritDoc |
133
|
|
|
*/ |
134
|
4 |
|
public function removeStream($stream) |
135
|
|
|
{ |
136
|
4 |
|
$this->loop->removeStream($stream); |
137
|
4 |
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @override |
141
|
|
|
* @inheritDoc |
142
|
|
|
*/ |
143
|
5 |
|
public function addTimer($interval, callable $callback) |
144
|
|
|
{ |
145
|
5 |
|
return $this->loop->addTimer($interval, $callback); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @override |
150
|
|
|
* @inheritDoc |
151
|
|
|
*/ |
152
|
2 |
|
public function addPeriodicTimer($interval, callable $callback) |
153
|
|
|
{ |
154
|
2 |
|
return $this->loop->addPeriodicTimer($interval, $callback); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @override |
159
|
|
|
* @inheritDoc |
160
|
|
|
*/ |
161
|
3 |
|
public function cancelTimer(TimerInterface $timer) |
162
|
|
|
{ |
163
|
3 |
|
$this->loop->cancelTimer($timer); |
164
|
3 |
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @override |
168
|
|
|
* @inheritDoc |
169
|
|
|
*/ |
170
|
3 |
|
public function isTimerActive(TimerInterface $timer) |
171
|
|
|
{ |
172
|
3 |
|
return $this->loop->isTimerActive($timer); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @override |
177
|
|
|
* @inheritDoc |
178
|
|
|
*/ |
179
|
2 |
|
public function onStart(callable $listener) |
180
|
|
|
{ |
181
|
2 |
|
$this->loop->onStart($listener); |
182
|
2 |
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @override |
186
|
|
|
* @inheritDoc |
187
|
|
|
*/ |
188
|
2 |
|
public function onStop(callable $listener) |
189
|
|
|
{ |
190
|
2 |
|
$this->loop->onStop($listener); |
191
|
2 |
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @override |
195
|
|
|
* @inheritDoc |
196
|
|
|
*/ |
197
|
1 |
|
public function onTick(callable $listener) |
198
|
|
|
{ |
199
|
1 |
|
$this->loop->onAfterTick($listener); |
200
|
1 |
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @override |
204
|
|
|
* @inheritDoc |
205
|
|
|
*/ |
206
|
5 |
|
public function onBeforeTick(callable $listener) |
207
|
|
|
{ |
208
|
5 |
|
$this->loop->onBeforeTick($listener); |
209
|
5 |
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @override |
213
|
|
|
* @inheritDoc |
214
|
|
|
*/ |
215
|
8 |
|
public function onAfterTick(callable $listener) |
216
|
|
|
{ |
217
|
8 |
|
$this->loop->onAfterTick($listener); |
218
|
8 |
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @override |
222
|
|
|
* @inheritDoc |
223
|
|
|
*/ |
224
|
15 |
|
public function tick() |
225
|
|
|
{ |
226
|
15 |
|
$this->loop->tick(); |
227
|
15 |
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @override |
231
|
|
|
* @inheritDoc |
232
|
|
|
*/ |
233
|
6 |
|
public function start() |
234
|
|
|
{ |
235
|
6 |
|
$this->loop->start(); |
236
|
6 |
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @override |
240
|
|
|
* @inheritDoc |
241
|
|
|
*/ |
242
|
6 |
|
public function stop() |
243
|
|
|
{ |
244
|
6 |
|
$this->loop->stop(); |
245
|
6 |
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @override |
249
|
|
|
* @inheritDoc |
250
|
|
|
*/ |
251
|
2 |
|
public function setFlowController($flowController) |
252
|
|
|
{ |
253
|
2 |
|
$this->loop->setFlowController($flowController); |
254
|
2 |
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @override |
258
|
|
|
* @inheritDoc |
259
|
|
|
*/ |
260
|
3 |
|
public function getFlowController() |
261
|
|
|
{ |
262
|
3 |
|
return $this->loop->getFlowController(); |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.