Skip to content

Update to require PHP 7.1+ #127

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

Merged
merged 3 commits into from
May 20, 2022
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
19 changes: 0 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ jobs:
- 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
Expand All @@ -34,17 +29,3 @@ jobs:
if: ${{ matrix.php >= 7.3 }}
- run: REDIS_URI=localhost:6379 vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
if: ${{ matrix.php < 7.3 }}

PHPUnit-hhvm:
name: PHPUnit (HHVM)
runs-on: ubuntu-18.04
continue-on-error: true
steps:
- uses: actions/checkout@v2
- uses: azjezz/setup-hhvm@v1
with:
version: lts-3.30
- run: composer self-update --2.2 # downgrade Composer for HHVM
- run: hhvm $(which composer) install
- run: docker run --net=host -d redis
- run: REDIS_URI=localhost:6379 hhvm vendor/bin/phpunit
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Async [Redis](https://redis.io/) client implementation, built on top of [ReactPH

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

```php
$channel = 'user';
$message = json_encode(array('id' => 10));
$message = json_encode(['id' => 10]);
$redis->publish($channel, $message);
```

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

```php
$connector = new React\Socket\Connector(array(
$connector = new React\Socket\Connector([
'dns' => '127.0.0.1',
'tcp' => array(
'tcp' => [
'bindto' => '192.168.10.1:0'
),
'tls' => array(
],
'tls' => [
'verify_peer' => false,
'verify_peer_name' => false
)
));
]
]);

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

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

We're committed to providing long-term support (LTS) options and to provide a
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": ">=5.3",
"php": ">=7.1",
"clue/redis-protocol": "0.3.*",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
"react/event-loop": "^1.2",
Expand All @@ -21,7 +21,7 @@
},
"require-dev": {
"clue/block-react": "^1.1",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
"phpunit/phpunit": "^9.3 || ^7.5"
},
"autoload": {
"psr-4": { "Clue\\React\\Redis\\": "src/" }
Expand Down
2 changes: 1 addition & 1 deletion examples/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

$params = explode(' ', $line);
$method = array_shift($params);
$promise = call_user_func_array(array($redis, $method), $params);
$promise = call_user_func_array([$redis, $method], $params);

// special method such as end() / close() called
if (!$promise instanceof React\Promise\PromiseInterface) {
Expand Down
4 changes: 2 additions & 2 deletions examples/publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
$factory = new Clue\React\Redis\Factory();
$redis = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379');

$channel = isset($argv[1]) ? $argv[1] : 'channel';
$message = isset($argv[2]) ? $argv[2] : 'message';
$channel = $argv[1] ?? 'channel';
$message = $argv[2] ?? 'message';

$redis->publish($channel, $message)->then(function ($received) {
echo 'Successfully published. Received by ' . $received . PHP_EOL;
Expand Down
2 changes: 1 addition & 1 deletion examples/subscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$factory = new Clue\React\Redis\Factory();
$redis = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379');

$channel = isset($argv[1]) ? $argv[1] : 'channel';
$channel = $argv[1] ?? 'channel';

$redis->subscribe($channel)->then(function () {
echo 'Now subscribed to channel ' . PHP_EOL;
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
Expand Down
30 changes: 15 additions & 15 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use React\Socket\ConnectionInterface;
use React\Socket\Connector;
use React\Socket\ConnectorInterface;
use function React\Promise\reject;
use function React\Promise\Timer\timeout;

class Factory
{
Expand All @@ -30,7 +32,7 @@ class Factory
public function __construct(LoopInterface $loop = null, ConnectorInterface $connector = null, ProtocolFactory $protocol = null)
{
$this->loop = $loop ?: Loop::get();
$this->connector = $connector ?: new Connector(array(), $this->loop);
$this->connector = $connector ?: new Connector([], $this->loop);
$this->protocol = $protocol ?: new ProtocolFactory();
}

Expand All @@ -54,18 +56,18 @@ public function createClient($uri)
$parts = parse_url($uri);
}

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

$args = array();
parse_str(isset($parts['query']) ? $parts['query'] : '', $args);
$args = [];
parse_str($parts['query'] ?? '', $args);

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

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

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

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

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

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

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