Skip to content

Commit e7fceec

Browse files
committed
Code style.
1 parent 3d078fd commit e7fceec

File tree

5 files changed

+32
-97
lines changed

5 files changed

+32
-97
lines changed

ExtEventLoop.php

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class ExtEventLoop implements LoopInterface
2727

2828
public function __construct()
2929
{
30-
$this->eventBase = new EventBase;
30+
$this->eventBase = new EventBase();
3131
$this->nextTickQueue = new NextTickQueue($this);
32-
$this->timerEvents = new SplObjectStorage;
32+
$this->timerEvents = new SplObjectStorage();
3333

3434
$this->createTimerCallback();
3535
$this->createStreamCallback();
@@ -175,7 +175,6 @@ public function run()
175175
$this->running = true;
176176

177177
while ($this->running) {
178-
179178
$this->nextTickQueue->tick();
180179

181180
if (!$this->streamEvents && !$this->timerEvents->count()) {
@@ -207,13 +206,8 @@ protected function scheduleTimer(TimerInterface $timer)
207206
$flags |= Event::PERSIST;
208207
}
209208

210-
$this->timerEvents[$timer] = $event = new Event(
211-
$this->eventBase,
212-
-1,
213-
$flags,
214-
$this->timerCallback,
215-
$timer
216-
);
209+
$event = new Event($this->eventBase, -1, $flags, $this->timerCallback, $timer);
210+
$this->timerEvents[$timer] = $event;
217211

218212
$event->add($timer->getInterval());
219213
}
@@ -230,22 +224,15 @@ protected function subscribeStreamEvent($stream, $flag)
230224

231225
if (isset($this->streamEvents[$key])) {
232226
$event = $this->streamEvents[$key];
227+
$flags = ($this->streamFlags[$key] |= $flag);
233228

234229
$event->del();
235-
236-
$event->set(
237-
$this->eventBase,
238-
$stream,
239-
Event::PERSIST | ($this->streamFlags[$key] |= $flag),
240-
$this->streamCallback
241-
);
230+
$event->set($this->eventBase, $stream, Event::PERSIST | $flags, $this->streamCallback);
242231
} else {
243-
$this->streamEvents[$key] = $event = new Event(
244-
$this->eventBase,
245-
$stream,
246-
Event::PERSIST | ($this->streamFlags[$key] = $flag),
247-
$this->streamCallback
248-
);
232+
$event = new Event($this->eventBase, $stream, Event::PERSIST | $flag, $this->streamCallback);
233+
234+
$this->streamEvents[$key] = $event;
235+
$this->streamFlags[$key] = $flag;
249236
}
250237

251238
$event->add();
@@ -273,14 +260,7 @@ protected function unsubscribeStreamEvent($stream, $flag)
273260
$event = $this->streamEvents[$key];
274261

275262
$event->del();
276-
277-
$event->set(
278-
$this->eventBase,
279-
$stream,
280-
Event::PERSIST | $flags,
281-
$this->streamCallback
282-
);
283-
263+
$event->set($this->eventBase, $stream, Event::PERSIST | $flags, $this->streamCallback);
284264
$event->add();
285265
}
286266

@@ -294,14 +274,11 @@ protected function unsubscribeStreamEvent($stream, $flag)
294274
protected function createTimerCallback()
295275
{
296276
$this->timerCallback = function ($_, $_, $timer) {
297-
298277
call_user_func($timer->getCallback(), $timer);
299278

300-
// Clean-up one shot timers ...
301279
if (!$timer->isPeriodic() && $this->isTimerActive($timer)) {
302280
$this->cancelTimer($timer);
303281
}
304-
305282
};
306283
}
307284

@@ -315,23 +292,15 @@ protected function createTimerCallback()
315292
protected function createStreamCallback()
316293
{
317294
$this->streamCallback = function ($stream, $flags) {
318-
319295
$key = (int) $stream;
320296

321-
if (
322-
Event::READ === (Event::READ & $flags)
323-
&& isset($this->readListeners[$key])
324-
) {
297+
if (Event::READ === (Event::READ & $flags) && isset($this->readListeners[$key])) {
325298
call_user_func($this->readListeners[$key], $stream, $this);
326299
}
327300

328-
if (
329-
Event::WRITE === (Event::WRITE & $flags)
330-
&& isset($this->writeListeners[$key])
331-
) {
301+
if (Event::WRITE === (Event::WRITE & $flags) && isset($this->writeListeners[$key])) {
332302
call_user_func($this->writeListeners[$key], $stream, $this);
333303
}
334-
335304
};
336305
}
337306
}

LibEvLoop.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class LibEvLoop implements LoopInterface
2525

2626
public function __construct()
2727
{
28-
$this->loop = new EventLoop;
28+
$this->loop = new EventLoop();
2929
$this->nextTickQueue = new NextTickQueue($this);
30-
$this->timers = new SplObjectStorage;
30+
$this->timers = new SplObjectStorage();
3131
}
3232

3333
/**

LibEventLoop.php

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct()
3131
{
3232
$this->eventBase = event_base_new();
3333
$this->nextTickQueue = new NextTickQueue($this);
34-
$this->timerEvents = new SplObjectStorage;
34+
$this->timerEvents = new SplObjectStorage();
3535

3636
$this->createTimerCallback();
3737
$this->createStreamCallback();
@@ -97,8 +97,8 @@ public function removeStream($stream)
9797
$key = (int) $stream;
9898

9999
if (isset($this->streamEvents[$key])) {
100-
101100
$event = $this->streamEvents[$key];
101+
102102
event_del($event);
103103
event_free($event);
104104

@@ -184,7 +184,6 @@ public function run()
184184
$this->running = true;
185185

186186
while ($this->running) {
187-
188187
$this->nextTickQueue->tick();
189188

190189
if (!$this->streamEvents && !$this->timerEvents->count()) {
@@ -213,13 +212,8 @@ protected function scheduleTimer(TimerInterface $timer)
213212
$this->timerEvents[$timer] = $event = event_timer_new();
214213

215214
event_timer_set($event, $this->timerCallback, $timer);
216-
217215
event_base_set($event, $this->eventBase);
218-
219-
event_add(
220-
$event,
221-
$timer->getInterval() * self::MICROSECONDS_PER_SECOND
222-
);
216+
event_add($event, $timer->getInterval() * self::MICROSECONDS_PER_SECOND);
223217
}
224218

225219
/**
@@ -234,26 +228,18 @@ protected function subscribeStreamEvent($stream, $flag)
234228

235229
if (isset($this->streamEvents[$key])) {
236230
$event = $this->streamEvents[$key];
231+
$flags = $this->streamFlags[$key] |= $flag;
237232

238233
event_del($event);
239-
240-
event_set(
241-
$event,
242-
$stream,
243-
EV_PERSIST | ($this->streamFlags[$key] |= $flag),
244-
$this->streamCallback
245-
);
234+
event_set($event, $stream, EV_PERSIST | $flags, $this->streamCallback);
246235
} else {
247-
$this->streamEvents[$key] = $event = event_new();
248-
249-
event_set(
250-
$event,
251-
$stream,
252-
EV_PERSIST | ($this->streamFlags[$key] = $flag),
253-
$this->streamCallback
254-
);
236+
$event = event_new();
255237

238+
event_set($event, $stream, EV_PERSIST | $flag, $this->streamCallback);
256239
event_base_set($event, $this->eventBase);
240+
241+
$this->streamEvents[$key] = $event;
242+
$this->streamFlags[$key] = $flag;
257243
}
258244

259245
event_add($event);
@@ -281,9 +267,7 @@ protected function unsubscribeStreamEvent($stream, $flag)
281267
$event = $this->streamEvents[$key];
282268

283269
event_del($event);
284-
285270
event_set($event, $stream, EV_PERSIST | $flags, $this->streamCallback);
286-
287271
event_add($event);
288272
}
289273

@@ -297,7 +281,6 @@ protected function unsubscribeStreamEvent($stream, $flag)
297281
protected function createTimerCallback()
298282
{
299283
$this->timerCallback = function ($_, $_, $timer) {
300-
301284
call_user_func($timer->getCallback(), $timer);
302285

303286
// Timer already cancelled ...
@@ -315,7 +298,6 @@ protected function createTimerCallback()
315298
} else {
316299
$this->cancelTimer($timer);
317300
}
318-
319301
};
320302
}
321303

@@ -329,23 +311,15 @@ protected function createTimerCallback()
329311
protected function createStreamCallback()
330312
{
331313
$this->streamCallback = function ($stream, $flags) {
332-
333314
$key = (int) $stream;
334315

335-
if (
336-
EV_READ === (EV_READ & $flags)
337-
&& isset($this->readListeners[$key])
338-
) {
316+
if (EV_READ === (EV_READ & $flags) && isset($this->readListeners[$key])) {
339317
call_user_func($this->readListeners[$key], $stream, $this);
340318
}
341319

342-
if (
343-
EV_WRITE === (EV_WRITE & $flags)
344-
&& isset($this->writeListeners[$key])
345-
) {
320+
if (EV_WRITE === (EV_WRITE & $flags) && isset($this->writeListeners[$key])) {
346321
call_user_func($this->writeListeners[$key], $stream, $this);
347322
}
348-
349323
};
350324
}
351325
}

StreamSelectLoop.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class StreamSelectLoop implements LoopInterface
2323
public function __construct()
2424
{
2525
$this->nextTickQueue = new NextTickQueue($this);
26-
$this->timers = new Timers;
26+
$this->timers = new Timers();
2727
}
2828

2929
/**
@@ -155,7 +155,6 @@ public function run()
155155
$this->running = true;
156156

157157
while ($this->running) {
158-
159158
$this->nextTickQueue->tick();
160159

161160
$this->timers->tick();
@@ -166,7 +165,6 @@ public function run()
166165

167166
// There is a pending timer, only block until it is due ...
168167
} elseif ($scheduledAt = $this->timers->getFirst()) {
169-
170168
if (0 > $timeout = $scheduledAt - $this->timers->getTime()) {
171169
$timeout = 0;
172170
}
@@ -202,7 +200,6 @@ protected function waitForStreamActivity($timeout)
202200

203201
$this->streamSelect($read, $write, $timeout);
204202

205-
// Invoke callbacks for read-ready streams ...
206203
foreach ($read as $stream) {
207204
$key = (int) $stream;
208205

@@ -211,7 +208,6 @@ protected function waitForStreamActivity($timeout)
211208
}
212209
}
213210

214-
// Invoke callbacks for write-ready streams ...
215211
foreach ($write as $stream) {
216212
$key = (int) $stream;
217213

@@ -228,19 +224,15 @@ protected function waitForStreamActivity($timeout)
228224
* @param array &$read An array of read streams to select upon.
229225
* @param array &$write An array of write streams to select upon.
230226
* @param integer|null $timeout Activity timeout in microseconds, or null to wait forever.
227+
*
228+
* @return integer The total number of streams that are ready for read/write.
231229
*/
232230
protected function streamSelect(array &$read, array &$write, $timeout)
233231
{
234232
if ($read || $write) {
235233
$except = null;
236234

237-
return stream_select(
238-
$read,
239-
$write,
240-
$except,
241-
$timeout === null ? null : 0,
242-
$timeout
243-
);
235+
return stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
244236
}
245237

246238
usleep($timeout);

Tick/NextTickQueue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class NextTickQueue
1616
public function __construct(LoopInterface $eventLoop)
1717
{
1818
$this->eventLoop = $eventLoop;
19-
$this->queue = new SplQueue;
19+
$this->queue = new SplQueue();
2020
}
2121

2222
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy