16
16
* that provides an interface to `libevent` library.
17
17
* `libevent` itself supports a number of system-specific backends (epoll, kqueue).
18
18
*
19
- * This loop is known to work with PHP 5.4 through PHP 8+.
19
+ * This loop is known to work with PHP 7.1 through PHP 8+.
20
20
*
21
21
* @link https://pecl.php.net/package/event
22
22
*/
@@ -27,15 +27,15 @@ final class ExtEventLoop implements LoopInterface
27
27
private $ timerCallback ;
28
28
private $ timerEvents ;
29
29
private $ streamCallback ;
30
- private $ readEvents = array () ;
31
- private $ writeEvents = array () ;
32
- private $ readListeners = array () ;
33
- private $ writeListeners = array () ;
34
- private $ readRefs = array () ;
35
- private $ writeRefs = array () ;
30
+ private $ readEvents = [] ;
31
+ private $ writeEvents = [] ;
32
+ private $ readListeners = [] ;
33
+ private $ writeListeners = [] ;
34
+ private $ readRefs = [] ;
35
+ private $ writeRefs = [] ;
36
36
private $ running ;
37
37
private $ signals ;
38
- private $ signalEvents = array () ;
38
+ private $ signalEvents = [] ;
39
39
40
40
public function __construct ()
41
41
{
@@ -67,8 +67,8 @@ public function __destruct()
67
67
$ this ->timerEvents ->detach ($ timer );
68
68
}
69
69
70
- $ this ->readEvents = array () ;
71
- $ this ->writeEvents = array () ;
70
+ $ this ->readEvents = [] ;
71
+ $ this ->writeEvents = [] ;
72
72
}
73
73
74
74
public function addReadStream ($ stream , $ listener )
@@ -85,9 +85,7 @@ public function addReadStream($stream, $listener)
85
85
86
86
// ext-event does not increase refcount on stream resources for PHP 7+
87
87
// manually keep track of stream resource to prevent premature garbage collection
88
- if (\PHP_VERSION_ID >= 70000 ) {
89
- $ this ->readRefs [$ key ] = $ stream ;
90
- }
88
+ $ this ->readRefs [$ key ] = $ stream ;
91
89
}
92
90
93
91
public function addWriteStream ($ stream , $ listener )
@@ -104,9 +102,7 @@ public function addWriteStream($stream, $listener)
104
102
105
103
// ext-event does not increase refcount on stream resources for PHP 7+
106
104
// manually keep track of stream resource to prevent premature garbage collection
107
- if (\PHP_VERSION_ID >= 70000 ) {
108
- $ this ->writeRefs [$ key ] = $ stream ;
109
- }
105
+ $ this ->writeRefs [$ key ] = $ stream ;
110
106
}
111
107
112
108
public function removeReadStream ($ stream )
@@ -173,7 +169,7 @@ public function addSignal($signal, $listener)
173
169
$ this ->signals ->add ($ signal , $ listener );
174
170
175
171
if (!isset ($ this ->signalEvents [$ signal ])) {
176
- $ this ->signalEvents [$ signal ] = Event::signal ($ this ->eventBase , $ signal , array ( $ this ->signals , 'call ' ) );
172
+ $ this ->signalEvents [$ signal ] = Event::signal ($ this ->eventBase , $ signal , [ $ this ->signals , 'call ' ] );
177
173
$ this ->signalEvents [$ signal ]->add ();
178
174
}
179
175
}
@@ -239,11 +235,10 @@ private function scheduleTimer(TimerInterface $timer)
239
235
*/
240
236
private function createTimerCallback ()
241
237
{
242
- $ timers = $ this ->timerEvents ;
243
- $ this ->timerCallback = function ($ _ , $ __ , $ timer ) use ($ timers ) {
238
+ $ this ->timerCallback = function ($ _ , $ __ , $ timer ) {
244
239
\call_user_func ($ timer ->getCallback (), $ timer );
245
240
246
- if (!$ timer ->isPeriodic () && $ timers ->contains ($ timer )) {
241
+ if (!$ timer ->isPeriodic () && $ this -> timerEvents ->contains ($ timer )) {
247
242
$ this ->cancelTimer ($ timer );
248
243
}
249
244
};
@@ -258,17 +253,15 @@ private function createTimerCallback()
258
253
*/
259
254
private function createStreamCallback ()
260
255
{
261
- $ read =& $ this ->readListeners ;
262
- $ write =& $ this ->writeListeners ;
263
- $ this ->streamCallback = function ($ stream , $ flags ) use (&$ read , &$ write ) {
256
+ $ this ->streamCallback = function ($ stream , $ flags ) {
264
257
$ key = (int ) $ stream ;
265
258
266
- if (Event::READ === (Event::READ & $ flags ) && isset ($ read [$ key ])) {
267
- \call_user_func ($ read [$ key ], $ stream );
259
+ if (Event::READ === (Event::READ & $ flags ) && isset ($ this -> readListeners [$ key ])) {
260
+ \call_user_func ($ this -> readListeners [$ key ], $ stream );
268
261
}
269
262
270
- if (Event::WRITE === (Event::WRITE & $ flags ) && isset ($ write [$ key ])) {
271
- \call_user_func ($ write [$ key ], $ stream );
263
+ if (Event::WRITE === (Event::WRITE & $ flags ) && isset ($ this -> writeListeners [$ key ])) {
264
+ \call_user_func ($ this -> writeListeners [$ key ], $ stream );
272
265
}
273
266
};
274
267
}
0 commit comments