Skip to content

Commit 75b1b96

Browse files
authored
Merge pull request #127 from clue-labs/php7.1
Update to require PHP 7.1+
2 parents ddbf8ac + 73b9460 commit 75b1b96

16 files changed

+352
-397
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ jobs:
1717
- 7.3
1818
- 7.2
1919
- 7.1
20-
- 7.0
21-
- 5.6
22-
- 5.5
23-
- 5.4
24-
- 5.3
2520
steps:
2621
- uses: actions/checkout@v2
2722
- uses: shivammathur/setup-php@v2
@@ -34,17 +29,3 @@ jobs:
3429
if: ${{ matrix.php >= 7.3 }}
3530
- run: REDIS_URI=localhost:6379 vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
3631
if: ${{ matrix.php < 7.3 }}
37-
38-
PHPUnit-hhvm:
39-
name: PHPUnit (HHVM)
40-
runs-on: ubuntu-18.04
41-
continue-on-error: true
42-
steps:
43-
- uses: actions/checkout@v2
44-
- uses: azjezz/setup-hhvm@v1
45-
with:
46-
version: lts-3.30
47-
- run: composer self-update --2.2 # downgrade Composer for HHVM
48-
- run: hhvm $(which composer) install
49-
- run: docker run --net=host -d redis
50-
- run: REDIS_URI=localhost:6379 hhvm vendor/bin/phpunit

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Async [Redis](https://redis.io/) client implementation, built on top of [ReactPH
77

88
> **Development version:** This branch contains the code for the upcoming 3.0 release.
99
> For the code of the current stable 2.x release, check out the
10-
> [`2.x` branch](https://github.com/reactphp/promise/tree/2.x).
10+
> [`2.x` branch](https://github.com/clue/reactphp-redis/tree/2.x).
1111
>
1212
> The upcoming 3.0 release will be the way forward for this package.
1313
> However, we will still actively support 2.x for those not yet
@@ -173,7 +173,7 @@ send a message to all clients currently subscribed to a given channel:
173173

174174
```php
175175
$channel = 'user';
176-
$message = json_encode(array('id' => 10));
176+
$message = json_encode(['id' => 10]);
177177
$redis->publish($channel, $message);
178178
```
179179

@@ -288,16 +288,16 @@ proxy servers etc.), you can explicitly pass a custom instance of the
288288
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface):
289289

290290
```php
291-
$connector = new React\Socket\Connector(array(
291+
$connector = new React\Socket\Connector([
292292
'dns' => '127.0.0.1',
293-
'tcp' => array(
293+
'tcp' => [
294294
'bindto' => '192.168.10.1:0'
295-
),
296-
'tls' => array(
295+
],
296+
'tls' => [
297297
'verify_peer' => false,
298298
'verify_peer_name' => false
299-
)
300-
));
299+
]
300+
]);
301301

302302
$factory = new Clue\React\Redis\Factory(null, $connector);
303303
```
@@ -625,8 +625,7 @@ $ composer require clue/redis-react:^3@dev
625625
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
626626

627627
This project aims to run on any platform and thus does not require any PHP
628-
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
629-
HHVM.
628+
extensions and supports running on PHP 7.1 through current PHP 8+.
630629
It's *highly recommended to use the latest supported PHP version* for this project.
631630

632631
We're committed to providing long-term support (LTS) options and to provide a

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=5.3",
14+
"php": ">=7.1",
1515
"clue/redis-protocol": "0.3.*",
1616
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
1717
"react/event-loop": "^1.2",
@@ -21,7 +21,7 @@
2121
},
2222
"require-dev": {
2323
"clue/block-react": "^1.1",
24-
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
24+
"phpunit/phpunit": "^9.3 || ^7.5"
2525
},
2626
"autoload": {
2727
"psr-4": { "Clue\\React\\Redis\\": "src/" }

examples/cli.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
$params = explode(' ', $line);
3131
$method = array_shift($params);
32-
$promise = call_user_func_array(array($redis, $method), $params);
32+
$promise = call_user_func_array([$redis, $method], $params);
3333

3434
// special method such as end() / close() called
3535
if (!$promise instanceof React\Promise\PromiseInterface) {

examples/publish.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
$factory = new Clue\React\Redis\Factory();
99
$redis = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379');
1010

11-
$channel = isset($argv[1]) ? $argv[1] : 'channel';
12-
$message = isset($argv[2]) ? $argv[2] : 'message';
11+
$channel = $argv[1] ?? 'channel';
12+
$message = $argv[2] ?? 'message';
1313

1414
$redis->publish($channel, $message)->then(function ($received) {
1515
echo 'Successfully published. Received by ' . $received . PHP_EOL;

examples/subscribe.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$factory = new Clue\React\Redis\Factory();
1111
$redis = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379');
1212

13-
$channel = isset($argv[1]) ? $argv[1] : 'channel';
13+
$channel = $argv[1] ?? 'channel';
1414

1515
$redis->subscribe($channel)->then(function () {
1616
echo 'Now subscribed to channel ' . PHP_EOL;

phpunit.xml.legacy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
3+
<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
66
bootstrap="vendor/autoload.php"
77
colors="true">
88
<testsuites>

src/Factory.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use React\Socket\ConnectionInterface;
1111
use React\Socket\Connector;
1212
use React\Socket\ConnectorInterface;
13+
use function React\Promise\reject;
14+
use function React\Promise\Timer\timeout;
1315

1416
class Factory
1517
{
@@ -30,7 +32,7 @@ class Factory
3032
public function __construct(LoopInterface $loop = null, ConnectorInterface $connector = null, ProtocolFactory $protocol = null)
3133
{
3234
$this->loop = $loop ?: Loop::get();
33-
$this->connector = $connector ?: new Connector(array(), $this->loop);
35+
$this->connector = $connector ?: new Connector([], $this->loop);
3436
$this->protocol = $protocol ?: new ProtocolFactory();
3537
}
3638

@@ -54,18 +56,18 @@ public function createClient($uri)
5456
$parts = parse_url($uri);
5557
}
5658

57-
$uri = preg_replace(array('/(:)[^:\/]*(@)/', '/([?&]password=).*?($|&)/'), '$1***$2', $uri);
58-
if ($parts === false || !isset($parts['scheme'], $parts['host']) || !in_array($parts['scheme'], array('redis', 'rediss', 'redis+unix'))) {
59-
return \React\Promise\reject(new \InvalidArgumentException(
59+
$uri = preg_replace(['/(:)[^:\/]*(@)/', '/([?&]password=).*?($|&)/'], '$1***$2', $uri);
60+
if ($parts === false || !isset($parts['scheme'], $parts['host']) || !in_array($parts['scheme'], ['redis', 'rediss', 'redis+unix'])) {
61+
return reject(new \InvalidArgumentException(
6062
'Invalid Redis URI given (EINVAL)',
6163
defined('SOCKET_EINVAL') ? SOCKET_EINVAL : 22
6264
));
6365
}
6466

65-
$args = array();
66-
parse_str(isset($parts['query']) ? $parts['query'] : '', $args);
67+
$args = [];
68+
parse_str($parts['query'] ?? '', $args);
6769

68-
$authority = $parts['host'] . ':' . (isset($parts['port']) ? $parts['port'] : 6379);
70+
$authority = $parts['host'] . ':' . ($parts['port'] ?? 6379);
6971
if ($parts['scheme'] === 'rediss') {
7072
$authority = 'tls://' . $authority;
7173
} elseif ($parts['scheme'] === 'redis+unix') {
@@ -88,9 +90,8 @@ public function createClient($uri)
8890
$connecting->cancel();
8991
});
9092

91-
$protocol = $this->protocol;
92-
$promise = $connecting->then(function (ConnectionInterface $stream) use ($protocol) {
93-
return new StreamingClient($stream, $protocol->createResponseParser(), $protocol->createSerializer());
93+
$promise = $connecting->then(function (ConnectionInterface $stream) {
94+
return new StreamingClient($stream, $this->protocol->createResponseParser(), $this->protocol->createSerializer());
9495
}, function (\Exception $e) use ($uri) {
9596
throw new \RuntimeException(
9697
'Connection to ' . $uri . ' failed: ' . $e->getMessage(),
@@ -100,9 +101,8 @@ public function createClient($uri)
100101
});
101102

102103
// use `?password=secret` query or `user:secret@host` password form URL
103-
$pass = isset($args['password']) ? $args['password'] : (isset($parts['pass']) ? rawurldecode($parts['pass']) : null);
104104
if (isset($args['password']) || isset($parts['pass'])) {
105-
$pass = isset($args['password']) ? $args['password'] : rawurldecode($parts['pass']);
105+
$pass = $args['password'] ?? rawurldecode($parts['pass']);
106106
$promise = $promise->then(function (StreamingClient $redis) use ($pass, $uri) {
107107
return $redis->auth($pass)->then(
108108
function () use ($redis) {
@@ -130,7 +130,7 @@ function (\Exception $e) use ($redis, $uri) {
130130

131131
// use `?db=1` query or `/1` path (skip first slash)
132132
if (isset($args['db']) || (isset($parts['path']) && $parts['path'] !== '/')) {
133-
$db = isset($args['db']) ? $args['db'] : substr($parts['path'], 1);
133+
$db = $args['db'] ?? substr($parts['path'], 1);
134134
$promise = $promise->then(function (StreamingClient $redis) use ($db, $uri) {
135135
return $redis->select($db)->then(
136136
function () use ($redis) {
@@ -159,15 +159,15 @@ function (\Exception $e) use ($redis, $uri) {
159159
});
160160
}
161161

162-
$promise->then(array($deferred, 'resolve'), array($deferred, 'reject'));
162+
$promise->then([$deferred, 'resolve'], [$deferred, 'reject']);
163163

164164
// use timeout from explicit ?timeout=x parameter or default to PHP's default_socket_timeout (60)
165165
$timeout = isset($args['timeout']) ? (float) $args['timeout'] : (int) ini_get("default_socket_timeout");
166166
if ($timeout < 0) {
167167
return $deferred->promise();
168168
}
169169

170-
return \React\Promise\Timer\timeout($deferred->promise(), $timeout, $this->loop)->then(null, function ($e) use ($uri) {
170+
return timeout($deferred->promise(), $timeout, $this->loop)->then(null, function ($e) use ($uri) {
171171
if ($e instanceof TimeoutException) {
172172
throw new \RuntimeException(
173173
'Connection to ' . $uri . ' timed out after ' . $e->getTimeout() . ' seconds (ETIMEDOUT)',

0 commit comments

Comments
 (0)