Skip to content

Commit dfca094

Browse files
authored
Merge pull request #46 from clue-labs/php8.4
Improve PHP 8.4+ support by avoiding implicitly nullable types
2 parents b4f0f9c + 560fecd commit dfca094

7 files changed

Lines changed: 35 additions & 8 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
php:
14+
- 8.4
1415
- 8.3
1516
- 8.2
1617
- 8.1

‎composer.json‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
"require": {
1414
"php": ">=5.3",
1515
"clue/socks-react": "^1.5",
16-
"react/child-process": "^0.6",
16+
"react/child-process": "^0.6.6",
1717
"react/event-loop": "^1.2",
18-
"react/promise": "^3 || ^2.1 || ^1.2.1",
19-
"react/socket": "^1.12.0",
20-
"react/stream": "^1.2"
18+
"react/promise": "^3.2 || ^2.11 || ^1.3",
19+
"react/socket": "^1.16",
20+
"react/stream": "^1.4"
2121
},
2222
"require-dev": {
2323
"phpunit/phpunit": "^9.6 || ^8.5 || ^5.7 || ^4.8.36",
24-
"react/async": "^4 || ^3 || ^2",
25-
"react/http": "^1.5",
24+
"react/async": "^4.3 || ^3.2 || ^2.2",
25+
"react/http": "^1.11",
2626
"react/mysql": "^0.5.5",
2727
"react/promise-timer": "^1.11"
2828
},

‎examples/31-mysql-ssh-tunnel.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
$proxy = new Clue\React\SshProxy\SshProcessConnector($url);
2121

2222
$url = getenv('MYSQL_LOGIN') !== false ? getenv('MYSQL_LOGIN') : 'user:pass@localhost';
23+
24+
// create MySQL factory without raising deprecation notice on PHP 8.4+
25+
// need this hack until react/mysql v0.7.0 ships https://github.com/friends-of-reactphp/mysql/pull/203
26+
set_error_handler(function () { }, E_DEPRECATED);
2327
$factory = new React\MySQL\Factory(null, $proxy);
28+
restore_error_handler();
29+
2430
$client = $factory->createLazyConnection($url);
2531

2632
$client->query('SELECT * FROM (SELECT "foo" UNION SELECT "bar") data')->then(function (React\MySQL\QueryResult $query) {

‎src/SshProcessConnector.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class SshProcessConnector implements ConnectorInterface
4141
public function __construct(
4242
#[\SensitiveParameter]
4343
$uri,
44-
LoopInterface $loop = null
44+
$loop = null
4545
) {
4646
// URI must use optional ssh:// scheme, must contain host and neither pass nor target must start with dash
4747
$parts = \parse_url((\strpos($uri, '://') === false ? 'ssh://' : '') . $uri);
@@ -51,6 +51,10 @@ public function __construct(
5151
throw new \InvalidArgumentException('Invalid SSH server URI');
5252
}
5353

54+
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
55+
throw new \InvalidArgumentException('Argument #2 ($loop) expected null|React\EventLoop\LoopInterface');
56+
}
57+
5458
$this->cmd = 'exec ';
5559
if ($pass !== null) {
5660
$this->cmd .= 'sshpass -p ' . \escapeshellarg($pass) . ' ';

‎src/SshSocksConnector.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SshSocksConnector implements ConnectorInterface
5252
public function __construct(
5353
#[\SensitiveParameter]
5454
$uri,
55-
LoopInterface $loop = null
55+
$loop = null
5656
) {
5757
// URI must use optional ssh:// scheme, must contain host and neither pass nor target must start with dash
5858
$parts = \parse_url((\strpos($uri, '://') === false ? 'ssh://' : '') . $uri);
@@ -62,6 +62,10 @@ public function __construct(
6262
throw new \InvalidArgumentException('Invalid SSH server URI');
6363
}
6464

65+
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
66+
throw new \InvalidArgumentException('Argument #2 ($loop) expected null|React\EventLoop\LoopInterface');
67+
}
68+
6569
$this->cmd = 'exec ';
6670
if ($pass !== null) {
6771
$this->cmd .= 'sshpass -p ' . \escapeshellarg($pass) . ' ';

‎tests/SshProcessConnectorTest.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ public function testConstructorThrowsForInvalidHost()
9393
new SshProcessConnector('-host', $loop);
9494
}
9595

96+
public function testConstructorThrowsForInvalidLoop()
97+
{
98+
$this->setExpectedException('InvalidArgumentException', 'Argument #2 ($loop) expected null|React\EventLoop\LoopInterface');
99+
new SshProcessConnector('host', 'loop');
100+
}
101+
96102
/**
97103
* @doesNotPerformAssertions
98104
*/

‎tests/SshSocksConnectorTest.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ public function testConstructorThrowsForInvalidBindHost()
123123
new SshSocksConnector('host?bind=example:1080', $loop);
124124
}
125125

126+
public function testConstructorThrowsForInvalidLoop()
127+
{
128+
$this->setExpectedException('InvalidArgumentException', 'Argument #2 ($loop) expected null|React\EventLoop\LoopInterface');
129+
new SshSocksConnector('host', 'loop');
130+
}
131+
126132
/**
127133
* @doesNotPerformAssertions
128134
*/

0 commit comments

Comments
 (0)