Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imported global functions #167

Merged
merged 4 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ExtEvLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function addReadStream($stream, $listener)
private function getStreamListenerClosure($stream, $listener)
{
return function () use ($stream, $listener) {
call_user_func($listener, $stream);
\call_user_func($listener, $stream);
};
}

Expand Down Expand Up @@ -140,7 +140,7 @@ public function addTimer($interval, $callback)
$that = $this;
$timers = $this->timers;
$callback = function () use ($timer, $timers, $that) {
call_user_func($timer->getCallback(), $timer);
\call_user_func($timer->getCallback(), $timer);

if ($timers->contains($timer)) {
$that->cancelTimer($timer);
Expand All @@ -158,7 +158,7 @@ public function addPeriodicTimer($interval, $callback)
$timer = new Timer($interval, $callback, true);

$callback = function () use ($timer) {
call_user_func($timer->getCallback(), $timer);
\call_user_func($timer->getCallback(), $timer);
};

$event = $this->loop->timer($interval, $interval, $callback);
Expand Down
12 changes: 6 additions & 6 deletions src/ExtEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class ExtEventLoop implements LoopInterface

public function __construct()
{
if (!class_exists('EventBase', false)) {
if (!\class_exists('EventBase', false)) {
throw new BadMethodCallException('Cannot create ExtEventLoop, ext-event extension missing');
}

Expand Down Expand Up @@ -69,7 +69,7 @@ public function addReadStream($stream, $listener)

// ext-event does not increase refcount on stream resources for PHP 7+
// manually keep track of stream resource to prevent premature garbage collection
if (PHP_VERSION_ID >= 70000) {
if (\PHP_VERSION_ID >= 70000) {
$this->readRefs[$key] = $stream;
}
}
Expand All @@ -88,7 +88,7 @@ public function addWriteStream($stream, $listener)

// ext-event does not increase refcount on stream resources for PHP 7+
// manually keep track of stream resource to prevent premature garbage collection
if (PHP_VERSION_ID >= 70000) {
if (\PHP_VERSION_ID >= 70000) {
$this->writeRefs[$key] = $stream;
}
}
Expand Down Expand Up @@ -225,7 +225,7 @@ private function createTimerCallback()
{
$timers = $this->timerEvents;
$this->timerCallback = function ($_, $__, $timer) use ($timers) {
call_user_func($timer->getCallback(), $timer);
\call_user_func($timer->getCallback(), $timer);

if (!$timer->isPeriodic() && $timers->contains($timer)) {
$this->cancelTimer($timer);
Expand All @@ -248,11 +248,11 @@ private function createStreamCallback()
$key = (int) $stream;

if (Event::READ === (Event::READ & $flags) && isset($read[$key])) {
call_user_func($read[$key], $stream);
\call_user_func($read[$key], $stream);
}

if (Event::WRITE === (Event::WRITE & $flags) && isset($write[$key])) {
call_user_func($write[$key], $stream);
\call_user_func($write[$key], $stream);
}
};
}
Expand Down
10 changes: 5 additions & 5 deletions src/ExtLibevLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class ExtLibevLoop implements LoopInterface

public function __construct()
{
if (!class_exists('libev\EventLoop', false)) {
if (!\class_exists('libev\EventLoop', false)) {
throw new BadMethodCallException('Cannot create ExtLibevLoop, ext-libev extension missing');
}

Expand All @@ -54,7 +54,7 @@ public function addReadStream($stream, $listener)
}

$callback = function () use ($stream, $listener) {
call_user_func($listener, $stream);
\call_user_func($listener, $stream);
};

$event = new IOEvent($callback, $stream, IOEvent::READ);
Expand All @@ -70,7 +70,7 @@ public function addWriteStream($stream, $listener)
}

$callback = function () use ($stream, $listener) {
call_user_func($listener, $stream);
\call_user_func($listener, $stream);
};

$event = new IOEvent($callback, $stream, IOEvent::WRITE);
Expand Down Expand Up @@ -108,7 +108,7 @@ public function addTimer($interval, $callback)
$that = $this;
$timers = $this->timerEvents;
$callback = function () use ($timer, $timers, $that) {
call_user_func($timer->getCallback(), $timer);
\call_user_func($timer->getCallback(), $timer);

if ($timers->contains($timer)) {
$that->cancelTimer($timer);
Expand All @@ -127,7 +127,7 @@ public function addPeriodicTimer($interval, $callback)
$timer = new Timer($interval, $callback, true);

$callback = function () use ($timer) {
call_user_func($timer->getCallback(), $timer);
\call_user_func($timer->getCallback(), $timer);
};

$event = new TimerEvent($callback, $interval, $interval);
Expand Down
70 changes: 35 additions & 35 deletions src/ExtLibeventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ final class ExtLibeventLoop implements LoopInterface

public function __construct()
{
if (!function_exists('event_base_new')) {
if (!\function_exists('event_base_new')) {
throw new BadMethodCallException('Cannot create ExtLibeventLoop, ext-libevent extension missing');
}

$this->eventBase = event_base_new();
$this->eventBase = \event_base_new();
$this->futureTickQueue = new FutureTickQueue();
$this->timerEvents = new SplObjectStorage();
$this->signals = new SignalsHandler();
Expand All @@ -73,10 +73,10 @@ public function addReadStream($stream, $listener)
return;
}

$event = event_new();
event_set($event, $stream, EV_PERSIST | EV_READ, $this->streamCallback);
event_base_set($event, $this->eventBase);
event_add($event);
$event = \event_new();
\event_set($event, $stream, \EV_PERSIST | \EV_READ, $this->streamCallback);
\event_base_set($event, $this->eventBase);
\event_add($event);

$this->readEvents[$key] = $event;
$this->readListeners[$key] = $listener;
Expand All @@ -89,10 +89,10 @@ public function addWriteStream($stream, $listener)
return;
}

$event = event_new();
event_set($event, $stream, EV_PERSIST | EV_WRITE, $this->streamCallback);
event_base_set($event, $this->eventBase);
event_add($event);
$event = \event_new();
\event_set($event, $stream, \EV_PERSIST | \EV_WRITE, $this->streamCallback);
\event_base_set($event, $this->eventBase);
\event_add($event);

$this->writeEvents[$key] = $event;
$this->writeListeners[$key] = $listener;
Expand All @@ -104,8 +104,8 @@ public function removeReadStream($stream)

if (isset($this->readListeners[$key])) {
$event = $this->readEvents[$key];
event_del($event);
event_free($event);
\event_del($event);
\event_free($event);

unset(
$this->readEvents[$key],
Expand All @@ -120,8 +120,8 @@ public function removeWriteStream($stream)

if (isset($this->writeListeners[$key])) {
$event = $this->writeEvents[$key];
event_del($event);
event_free($event);
\event_del($event);
\event_free($event);

unset(
$this->writeEvents[$key],
Expand Down Expand Up @@ -152,8 +152,8 @@ public function cancelTimer(TimerInterface $timer)
{
if ($this->timerEvents->contains($timer)) {
$event = $this->timerEvents[$timer];
event_del($event);
event_free($event);
\event_del($event);
\event_free($event);

$this->timerEvents->detach($timer);
}
Expand All @@ -169,10 +169,10 @@ public function addSignal($signal, $listener)
$this->signals->add($signal, $listener);

if (!isset($this->signalEvents[$signal])) {
$this->signalEvents[$signal] = event_new();
event_set($this->signalEvents[$signal], $signal, EV_PERSIST | EV_SIGNAL, array($this->signals, 'call'));
event_base_set($this->signalEvents[$signal], $this->eventBase);
event_add($this->signalEvents[$signal]);
$this->signalEvents[$signal] = \event_new();
\event_set($this->signalEvents[$signal], $signal, \EV_PERSIST | \EV_SIGNAL, array($this->signals, 'call'));
\event_base_set($this->signalEvents[$signal], $this->eventBase);
\event_add($this->signalEvents[$signal]);
}
}

Expand All @@ -181,8 +181,8 @@ public function removeSignal($signal, $listener)
$this->signals->remove($signal, $listener);

if (isset($this->signalEvents[$signal]) && $this->signals->count($signal) === 0) {
event_del($this->signalEvents[$signal]);
event_free($this->signalEvents[$signal]);
\event_del($this->signalEvents[$signal]);
\event_free($this->signalEvents[$signal]);
unset($this->signalEvents[$signal]);
}
}
Expand All @@ -194,14 +194,14 @@ public function run()
while ($this->running) {
$this->futureTickQueue->tick();

$flags = EVLOOP_ONCE;
$flags = \EVLOOP_ONCE;
if (!$this->running || !$this->futureTickQueue->isEmpty()) {
$flags |= EVLOOP_NONBLOCK;
$flags |= \EVLOOP_NONBLOCK;
} elseif (!$this->readEvents && !$this->writeEvents && !$this->timerEvents->count() && $this->signals->isEmpty()) {
break;
}

event_base_loop($this->eventBase, $flags);
\event_base_loop($this->eventBase, $flags);
}
}

Expand All @@ -217,11 +217,11 @@ public function stop()
*/
private function scheduleTimer(TimerInterface $timer)
{
$this->timerEvents[$timer] = $event = event_timer_new();
$this->timerEvents[$timer] = $event = \event_timer_new();

event_timer_set($event, $this->timerCallback, $timer);
event_base_set($event, $this->eventBase);
event_add($event, $timer->getInterval() * self::MICROSECONDS_PER_SECOND);
\event_timer_set($event, $this->timerCallback, $timer);
\event_base_set($event, $this->eventBase);
\event_add($event, $timer->getInterval() * self::MICROSECONDS_PER_SECOND);
}

/**
Expand All @@ -236,7 +236,7 @@ private function createTimerCallback()
$that = $this;
$timers = $this->timerEvents;
$this->timerCallback = function ($_, $__, $timer) use ($timers, $that) {
call_user_func($timer->getCallback(), $timer);
\call_user_func($timer->getCallback(), $timer);

// Timer already cancelled ...
if (!$timers->contains($timer)) {
Expand All @@ -245,7 +245,7 @@ private function createTimerCallback()

// Reschedule periodic timers ...
if ($timer->isPeriodic()) {
event_add(
\event_add(
$timers[$timer],
$timer->getInterval() * ExtLibeventLoop::MICROSECONDS_PER_SECOND
);
Expand All @@ -271,12 +271,12 @@ private function createStreamCallback()
$this->streamCallback = function ($stream, $flags) use (&$read, &$write) {
$key = (int) $stream;

if (EV_READ === (EV_READ & $flags) && isset($read[$key])) {
call_user_func($read[$key], $stream);
if (\EV_READ === (\EV_READ & $flags) && isset($read[$key])) {
\call_user_func($read[$key], $stream);
}

if (EV_WRITE === (EV_WRITE & $flags) && isset($write[$key])) {
call_user_func($write[$key], $stream);
if (\EV_WRITE === (\EV_WRITE & $flags) && isset($write[$key])) {
\call_user_func($write[$key], $stream);
}
};
}
Expand Down
8 changes: 4 additions & 4 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ final class Factory
public static function create()
{
// @codeCoverageIgnoreStart
if (class_exists('libev\EventLoop', false)) {
if (\class_exists('libev\EventLoop', false)) {
return new ExtLibevLoop();
} elseif (class_exists('EvLoop', false)) {
} elseif (\class_exists('EvLoop', false)) {
return new ExtEvLoop();
} elseif (class_exists('EventBase', false)) {
} elseif (\class_exists('EventBase', false)) {
return new ExtEventLoop();
} elseif (function_exists('event_base_new') && PHP_VERSION_ID < 70000) {
} elseif (\function_exists('event_base_new') && \PHP_VERSION_ID < 70000) {
// only use ext-libevent on PHP < 7 for now
return new ExtLibeventLoop();
}
Expand Down
2 changes: 1 addition & 1 deletion src/SignalsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function add($signal, $listener)
$this->signals[$signal] = array();
}

if (in_array($listener, $this->signals[$signal])) {
if (\in_array($listener, $this->signals[$signal])) {
return;
}

Expand Down
14 changes: 7 additions & 7 deletions src/StreamSelectLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct()
{
$this->futureTickQueue = new FutureTickQueue();
$this->timers = new Timers();
$this->pcntl = extension_loaded('pcntl');
$this->pcntl = \extension_loaded('pcntl');
$this->signals = new SignalsHandler();
}

Expand Down Expand Up @@ -163,7 +163,7 @@ public function removeSignal($signal, $listener)
$this->signals->remove($signal, $listener);

if ($this->signals->count($signal) === 0) {
\pcntl_signal($signal, SIG_DFL);
\pcntl_signal($signal, \SIG_DFL);
}
}

Expand All @@ -190,7 +190,7 @@ public function run()
// Ensure we do not exceed maximum integer size, which may
// cause the loop to tick once every ~35min on 32bit systems.
$timeout *= self::MICROSECONDS_PER_SECOND;
$timeout = $timeout > PHP_INT_MAX ? PHP_INT_MAX : (int)$timeout;
$timeout = $timeout > \PHP_INT_MAX ? \PHP_INT_MAX : (int)$timeout;
}

// The only possible event is stream or signal activity, so wait forever ...
Expand Down Expand Up @@ -235,15 +235,15 @@ private function waitForStreamActivity($timeout)
$key = (int) $stream;

if (isset($this->readListeners[$key])) {
call_user_func($this->readListeners[$key], $stream);
\call_user_func($this->readListeners[$key], $stream);
}
}

foreach ($write as $stream) {
$key = (int) $stream;

if (isset($this->writeListeners[$key])) {
call_user_func($this->writeListeners[$key], $stream);
\call_user_func($this->writeListeners[$key], $stream);
}
}
}
Expand All @@ -265,10 +265,10 @@ private function streamSelect(array &$read, array &$write, $timeout)
$except = null;

// suppress warnings that occur, when stream_select is interrupted by a signal
return @stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
return @\stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
}

$timeout && usleep($timeout);
$timeout && \usleep($timeout);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tick/FutureTickQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function tick()
$count = $this->queue->count();

while ($count--) {
call_user_func(
\call_user_func(
$this->queue->dequeue()
);
}
Expand Down
Loading