Skip to content

Commit c7a58c0

Browse files
committed
[RFC] Improve compatibility with legacy versions
1 parent 14c870e commit c7a58c0

11 files changed

+126
-95
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: php
22

33
php:
4+
# - 5.3 # requires old distro, see below
45
- 5.4
56
- 5.5
67
- 5.6
@@ -13,6 +14,9 @@ php:
1314
dist: trusty
1415

1516
matrix:
17+
include:
18+
- php: 5.3
19+
dist: precise
1620
allow_failures:
1721
- php: hhvm
1822

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ A `stream_select()` based event loop.
158158
This uses the [`stream_select()`](http://php.net/manual/en/function.stream-select.php)
159159
function and is the only implementation which works out of the box with PHP.
160160

161-
This event loop works out of the box on PHP 5.4 through PHP 7+ and HHVM.
161+
This event loop works out of the box on PHP 5.3 through PHP 7+ and HHVM.
162162
This means that no installation is required and this library works on all
163163
platforms and supported PHP versions.
164164
Accordingly, the [`Factory`](#factory) will use this event loop by default if
@@ -199,7 +199,7 @@ An `ext-event` based event loop.
199199
This uses the [`event` PECL extension](https://pecl.php.net/package/event).
200200
It supports the same backends as libevent.
201201

202-
This loop is known to work with PHP 5.4 through PHP 7+.
202+
This loop is known to work with PHP 5.3 through PHP 7+.
203203

204204
#### ExtLibeventLoop
205205

@@ -574,7 +574,7 @@ $ composer require react/event-loop
574574
```
575575

576576
This project aims to run on any platform and thus does not require any PHP
577-
extensions and supports running on legacy PHP 5.4 through current PHP 7+ and
577+
extensions and supports running on legacy PHP 5.3 through current PHP 7+ and
578578
HHVM.
579579
It's *highly recommended to use PHP 7+* for this project.
580580

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"keywords": ["event-loop", "asynchronous"],
55
"license": "MIT",
66
"require": {
7-
"php": ">=5.4.0"
7+
"php": ">=5.3.0"
88
},
99
"require-dev": {
1010
"phpunit/phpunit": "~4.8.35 || ^5.7 || ^6.4"

src/ExtEventLoop.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* This uses the [`event` PECL extension](https://pecl.php.net/package/event).
1616
* It supports the same backends as libevent.
1717
*
18-
* This loop is known to work with PHP 5.4 through PHP 7+.
18+
* This loop is known to work with PHP 5.3 through PHP 7+.
1919
*
2020
* @link https://pecl.php.net/package/event
2121
*/
@@ -26,15 +26,15 @@ final class ExtEventLoop implements LoopInterface
2626
private $timerCallback;
2727
private $timerEvents;
2828
private $streamCallback;
29-
private $readEvents = [];
30-
private $writeEvents = [];
31-
private $readListeners = [];
32-
private $writeListeners = [];
33-
private $readRefs = [];
34-
private $writeRefs = [];
29+
private $readEvents = array();
30+
private $writeEvents = array();
31+
private $readListeners = array();
32+
private $writeListeners = array();
33+
private $readRefs = array();
34+
private $writeRefs = array();
3535
private $running;
3636
private $signals;
37-
private $signalEvents = [];
37+
private $signalEvents = array();
3838

3939
public function __construct(EventBaseConfig $config = null)
4040
{
@@ -215,10 +215,11 @@ private function scheduleTimer(TimerInterface $timer)
215215
*/
216216
private function createTimerCallback()
217217
{
218-
$this->timerCallback = function ($_, $__, $timer) {
218+
$timers = $this->timerEvents;
219+
$this->timerCallback = function ($_, $__, $timer) use ($timers) {
219220
call_user_func($timer->getCallback(), $timer);
220221

221-
if (!$timer->isPeriodic() && $this->timerEvents->contains($timer)) {
222+
if (!$timer->isPeriodic() && $timers->contains($timer)) {
222223
$this->cancelTimer($timer);
223224
}
224225
};
@@ -233,15 +234,17 @@ private function createTimerCallback()
233234
*/
234235
private function createStreamCallback()
235236
{
236-
$this->streamCallback = function ($stream, $flags) {
237+
$read =& $this->readListeners;
238+
$write =& $this->writeListeners;
239+
$this->streamCallback = function ($stream, $flags) use (&$read, &$write) {
237240
$key = (int) $stream;
238241

239-
if (Event::READ === (Event::READ & $flags) && isset($this->readListeners[$key])) {
240-
call_user_func($this->readListeners[$key], $stream);
242+
if (Event::READ === (Event::READ & $flags) && isset($read[$key])) {
243+
call_user_func($read[$key], $stream);
241244
}
242245

243-
if (Event::WRITE === (Event::WRITE & $flags) && isset($this->writeListeners[$key])) {
244-
call_user_func($this->writeListeners[$key], $stream);
246+
if (Event::WRITE === (Event::WRITE & $flags) && isset($write[$key])) {
247+
call_user_func($write[$key], $stream);
245248
}
246249
};
247250
}

src/ExtLibevLoop.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ final class ExtLibevLoop implements LoopInterface
2828
private $loop;
2929
private $futureTickQueue;
3030
private $timerEvents;
31-
private $readEvents = [];
32-
private $writeEvents = [];
31+
private $readEvents = array();
32+
private $writeEvents = array();
3333
private $running;
3434
private $signals;
35-
private $signalEvents = [];
35+
private $signalEvents = array();
3636

3737
public function __construct()
3838
{
@@ -100,10 +100,11 @@ public function addTimer($interval, $callback)
100100
{
101101
$timer = new Timer( $interval, $callback, false);
102102

103-
$callback = function () use ($timer) {
103+
$timers = $this->timerEvents;
104+
$callback = function () use ($timer, $timers) {
104105
call_user_func($timer->getCallback(), $timer);
105106

106-
if ($this->timerEvents->contains($timer)) {
107+
if ($timers->contains($timer)) {
107108
$this->cancelTimer($timer);
108109
}
109110
};
@@ -148,8 +149,9 @@ public function addSignal($signal, $listener)
148149
$this->signals->add($signal, $listener);
149150

150151
if (!isset($this->signalEvents[$signal])) {
151-
$this->signalEvents[$signal] = new SignalEvent(function () use ($signal) {
152-
$this->signals->call($signal);
152+
$signals = $this->signals;
153+
$this->signalEvents[$signal] = new SignalEvent(function () use ($signals, $signal) {
154+
$signals->call($signal);
153155
}, $signal);
154156
$this->loop->add($this->signalEvents[$signal]);
155157
}

src/ExtLibeventLoop.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ final class ExtLibeventLoop implements LoopInterface
4242
private $timerCallback;
4343
private $timerEvents;
4444
private $streamCallback;
45-
private $readEvents = [];
46-
private $writeEvents = [];
47-
private $readListeners = [];
48-
private $writeListeners = [];
45+
private $readEvents = array();
46+
private $writeEvents = array();
47+
private $readListeners = array();
48+
private $writeListeners = array();
4949
private $running;
5050
private $signals;
51-
private $signalEvents = [];
51+
private $signalEvents = array();
5252

5353
public function __construct()
5454
{
@@ -228,18 +228,19 @@ private function scheduleTimer(TimerInterface $timer)
228228
*/
229229
private function createTimerCallback()
230230
{
231-
$this->timerCallback = function ($_, $__, $timer) {
231+
$timers = $this->timerEvents;
232+
$this->timerCallback = function ($_, $__, $timer) use ($timers) {
232233
call_user_func($timer->getCallback(), $timer);
233234

234235
// Timer already cancelled ...
235-
if (!$this->timerEvents->contains($timer)) {
236+
if (!$timers->contains($timer)) {
236237
return;
237238
}
238239

239240
// Reschedule periodic timers ...
240241
if ($timer->isPeriodic()) {
241242
event_add(
242-
$this->timerEvents[$timer],
243+
$timers[$timer],
243244
$timer->getInterval() * self::MICROSECONDS_PER_SECOND
244245
);
245246

@@ -259,15 +260,17 @@ private function createTimerCallback()
259260
*/
260261
private function createStreamCallback()
261262
{
262-
$this->streamCallback = function ($stream, $flags) {
263+
$read =& $this->readListeners;
264+
$write =& $this->writeListeners;
265+
$this->streamCallback = function ($stream, $flags) use (&$read, &$write) {
263266
$key = (int) $stream;
264267

265-
if (EV_READ === (EV_READ & $flags) && isset($this->readListeners[$key])) {
266-
call_user_func($this->readListeners[$key], $stream);
268+
if (EV_READ === (EV_READ & $flags) && isset($read[$key])) {
269+
call_user_func($read[$key], $stream);
267270
}
268271

269-
if (EV_WRITE === (EV_WRITE & $flags) && isset($this->writeListeners[$key])) {
270-
call_user_func($this->writeListeners[$key], $stream);
272+
if (EV_WRITE === (EV_WRITE & $flags) && isset($write[$key])) {
273+
call_user_func($write[$key], $stream);
271274
}
272275
};
273276
}

src/SignalsHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
*/
88
final class SignalsHandler
99
{
10-
private $signals = [];
10+
private $signals = array();
1111

1212
public function add($signal, $listener)
1313
{
1414
if (!isset($this->signals[$signal])) {
15-
$this->signals[$signal] = [];
15+
$this->signals[$signal] = array();
1616
}
1717

1818
if (in_array($listener, $this->signals[$signal])) {

src/StreamSelectLoop.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ final class StreamSelectLoop implements LoopInterface
5656

5757
private $futureTickQueue;
5858
private $timers;
59-
private $readStreams = [];
60-
private $readListeners = [];
61-
private $writeStreams = [];
62-
private $writeListeners = [];
59+
private $readStreams = array();
60+
private $readListeners = array();
61+
private $writeStreams = array();
62+
private $writeListeners = array();
6363
private $running;
6464
private $pcntl = false;
6565
private $signals;

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