Skip to content

Commit b9c9e69

Browse files
committed
support for older versions php
1 parent 07d5e91 commit b9c9e69

File tree

7 files changed

+30
-17
lines changed

7 files changed

+30
-17
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
- ubuntu-latest
3232

3333
php:
34+
- "7.3"
35+
- "7.4"
36+
- "8.0"
3437
- "8.1"
3538
- "8.2"
3639
- "8.3"

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
}
2525
],
2626
"require": {
27-
"php": ">=8.1",
27+
"php": "^7.2 || ^8.0",
2828
"yiisoft/yii2": "~2.0.51",
2929
"ext-openssl": "*",
30-
"predis/predis": "^3.0"
30+
"predis/predis": "^v2.3.0|^3.0"
3131
},
3232
"require-dev": {
3333
"phpunit/phpunit": "9.*",

src/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ public function __call($name, $params)
545545
* for details on the mentioned reply types.
546546
* @throws Exception for commands that return [error reply](https://redis.io/topics/protocol#error-reply).
547547
*/
548-
public function executeCommand($name, $params = []): mixed
548+
public function executeCommand($name, $params = [])
549549
{
550550
$this->open();
551551

src/ConnectionInterface.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,5 +225,10 @@ public function close(): void;
225225

226226
public function getIsActive(): bool;
227227

228-
public function executeCommand($name, $params = []): mixed;
228+
/**
229+
* @param $name
230+
* @param $params
231+
* @return mixed
232+
*/
233+
public function executeCommand($name, $params = []);
229234
}

src/predis/Command/CommandDecorator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class CommandDecorator extends COMMAND
1010
{
11-
private CommandInterface $originalCommand;
11+
private $originalCommand;
1212

1313
public function __construct(CommandInterface $command)
1414
{
@@ -26,7 +26,7 @@ public function parseResponse($data)
2626

2727
// Calling methods of the original class
2828

29-
public function __call($method, $args): mixed { return call_user_func_array([$this->originalCommand, $method], $args); }
29+
public function __call($method, $args) { return call_user_func_array([$this->originalCommand, $method], $args); }
3030

3131
public function getId():string { return $this->originalCommand->getId(); }
3232

@@ -40,9 +40,9 @@ public function getSlot(): ?int { return $this->originalCommand->getSlot(); }
4040

4141
public function setRawArguments(array $arguments): void { $this->originalCommand->setRawArguments($arguments); }
4242

43-
public function getArgument($index): mixed { return $this->originalCommand->getArgument($index); }
43+
public function getArgument($index) { return $this->originalCommand->getArgument($index); }
4444

45-
public function parseResp3Response($data): mixed { return $this->originalCommand->parseResp3Response($data); }
45+
public function parseResp3Response($data) { return $this->originalCommand->parseResp3Response($data); }
4646

4747
public function serializeCommand(): string { return $this->originalCommand->serializeCommand(); }
4848
}

src/predis/PredisConnection.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class PredisConnection extends Component implements ConnectionInterface
5454
* @var array List of available redis commands.
5555
* @see https://redis.io/commands
5656
*/
57-
public array $redisCommands = [
57+
public $redisCommands = [
5858
'APPEND', // Append a value to a key
5959
'AUTH', // Authenticate to the server
6060
'BGREWRITEAOF', // Asynchronously rewrite the append-only file
@@ -289,17 +289,17 @@ protected function initConnection(): void
289289
/**
290290
* @var mixed Connection parameters for one or more servers.
291291
*/
292-
public mixed $parameters;
292+
public $parameters;
293293

294294
/**
295295
* @var mixed Options to configure some behaviours of the client.
296296
*/
297-
public mixed $options = [];
297+
public $options = [];
298298

299299
/**
300300
* @var Client|null redis connection
301301
*/
302-
protected Client|null $client = null;
302+
protected $client;
303303

304304
/**
305305
* Returns a value indicating whether the DB connection is established.
@@ -308,14 +308,17 @@ protected function initConnection(): void
308308
*/
309309
public function getIsActive(): bool
310310
{
311-
return (bool)$this->client?->isConnected();
311+
if($this->client === null) {
312+
return false;
313+
}
314+
return $this->client->isConnected();
312315
}
313316

314317
/**
315318
* @return mixed|ErrorInterface|ResponseInterface
316319
* @throws InvalidConfigException
317320
*/
318-
public function executeCommand($name, $params = []): mixed
321+
public function executeCommand($name, $params = [])
319322
{
320323
$this->open();
321324

@@ -359,7 +362,10 @@ public function open(): void
359362
*/
360363
public function close(): void
361364
{
362-
$this->client?->disconnect();
365+
if($this->client === null) {
366+
return;
367+
}
368+
$this->client->disconnect();
363369
}
364370

365371
/**
@@ -386,7 +392,7 @@ public function getClient(): ?Client
386392
* @return mixed
387393
* @throws InvalidConfigException
388394
*/
389-
public function __call($name, $params): mixed
395+
public function __call($name, $params)
390396
{
391397
$redisCommand = strtoupper(Inflector::camel2words($name, false));
392398
if (in_array($redisCommand, $this->redisCommands, true)) {

tests/data/ar/OrderItem.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,4 @@ public function getItem()
4646
{
4747
return $this->hasOne(Item::className(), ['id' => 'item_id']);
4848
}
49-
5049
}

0 commit comments

Comments
 (0)