Skip to content

Commit c8c9d42

Browse files
committed
Update PHP language syntax and remove legacy workarounds
1 parent d15b8df commit c8c9d42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+853
-870
lines changed

README.md

+55-55
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,13 @@ Optionally, you can specify [TCP socket context options](https://www.php.net/man
423423
for the underlying stream socket resource like this:
424424

425425
```php
426-
$socket = new React\Socket\SocketServer('[::1]:8080', array(
427-
'tcp' => array(
426+
$socket = new React\Socket\SocketServer('[::1]:8080', [
427+
'tcp' => [
428428
'backlog' => 200,
429429
'so_reuseport' => true,
430430
'ipv6_v6only' => true
431-
)
432-
));
431+
]
432+
]);
433433
```
434434

435435
> Note that available [socket context options](https://www.php.net/manual/en/context.socket.php),
@@ -447,11 +447,11 @@ which in its most basic form may look something like this if you're using a
447447
PEM encoded certificate file:
448448

449449
```php
450-
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8080', array(
451-
'tls' => array(
450+
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8080', [
451+
'tls' => [
452452
'local_cert' => 'server.pem'
453-
)
454-
));
453+
]
454+
]);
455455
```
456456

457457
> Note that the certificate file will not be loaded on instantiation but when an
@@ -463,25 +463,25 @@ If your private key is encrypted with a passphrase, you have to specify it
463463
like this:
464464

465465
```php
466-
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', array(
467-
'tls' => array(
466+
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', [
467+
'tls' => [
468468
'local_cert' => 'server.pem',
469469
'passphrase' => 'secret'
470-
)
471-
));
470+
]
471+
]);
472472
```
473473

474474
By default, this server supports TLSv1.0+ and excludes support for legacy
475475
SSLv2/SSLv3. You can also explicitly choose the TLS version you
476476
want to negotiate with the remote side:
477477

478478
```php
479-
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', array(
480-
'tls' => array(
479+
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', [
480+
'tls' => [
481481
'local_cert' => 'server.pem',
482482
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER
483-
)
484-
));
483+
]
484+
]);
485485
```
486486

487487
> Note that available [TLS context options](https://www.php.net/manual/en/context.ssl.php),
@@ -588,11 +588,11 @@ Optionally, you can specify [socket context options](https://www.php.net/manual/
588588
for the underlying stream socket resource like this:
589589

590590
```php
591-
$server = new React\Socket\TcpServer('[::1]:8080', null, array(
591+
$server = new React\Socket\TcpServer('[::1]:8080', null, [
592592
'backlog' => 200,
593593
'so_reuseport' => true,
594594
'ipv6_v6only' => true
595-
));
595+
]);
596596
```
597597

598598
> Note that available [socket context options](https://www.php.net/manual/en/context.socket.php),
@@ -628,9 +628,9 @@ PEM encoded certificate file:
628628

629629
```php
630630
$server = new React\Socket\TcpServer(8000);
631-
$server = new React\Socket\SecureServer($server, null, array(
631+
$server = new React\Socket\SecureServer($server, null, [
632632
'local_cert' => 'server.pem'
633-
));
633+
]);
634634
```
635635

636636
> Note that the certificate file will not be loaded on instantiation but when an
@@ -643,10 +643,10 @@ like this:
643643

644644
```php
645645
$server = new React\Socket\TcpServer(8000);
646-
$server = new React\Socket\SecureServer($server, null, array(
646+
$server = new React\Socket\SecureServer($server, null, [
647647
'local_cert' => 'server.pem',
648648
'passphrase' => 'secret'
649-
));
649+
]);
650650
```
651651

652652
By default, this server supports TLSv1.0+ and excludes support for legacy
@@ -655,10 +655,10 @@ want to negotiate with the remote side:
655655

656656
```php
657657
$server = new React\Socket\TcpServer(8000);
658-
$server = new React\Socket\SecureServer($server, null, array(
658+
$server = new React\Socket\SecureServer($server, null, [
659659
'local_cert' => 'server.pem',
660660
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER
661-
));
661+
]);
662662
```
663663

664664
> Note that available [TLS context options](https://www.php.net/manual/en/context.ssl.php),
@@ -971,9 +971,9 @@ If you want to revert to the old behavior of only doing an IPv4 lookup and
971971
only attempt a single IPv4 connection, you can set up the `Connector` like this:
972972

973973
```php
974-
$connector = new React\Socket\Connector(array(
974+
$connector = new React\Socket\Connector([
975975
'happy_eyeballs' => false
976-
));
976+
]);
977977
```
978978

979979
Similarly, you can also affect the default DNS behavior as follows.
@@ -985,9 +985,9 @@ If you explicitly want to use a custom DNS server (such as a local DNS relay or
985985
a company wide DNS server), you can set up the `Connector` like this:
986986

987987
```php
988-
$connector = new React\Socket\Connector(array(
988+
$connector = new React\Socket\Connector([
989989
'dns' => '127.0.1.1'
990-
));
990+
]);
991991

992992
$connector->connect('localhost:80')->then(function (React\Socket\ConnectionInterface $connection) {
993993
$connection->write('...');
@@ -999,9 +999,9 @@ If you do not want to use a DNS resolver at all and want to connect to IP
999999
addresses only, you can also set up your `Connector` like this:
10001000

10011001
```php
1002-
$connector = new React\Socket\Connector(array(
1002+
$connector = new React\Socket\Connector([
10031003
'dns' => false
1004-
));
1004+
]);
10051005

10061006
$connector->connect('127.0.0.1:80')->then(function (React\Socket\ConnectionInterface $connection) {
10071007
$connection->write('...');
@@ -1016,9 +1016,9 @@ can also set up your `Connector` like this:
10161016
$dnsResolverFactory = new React\Dns\Resolver\Factory();
10171017
$resolver = $dnsResolverFactory->createCached('127.0.1.1');
10181018

1019-
$connector = new React\Socket\Connector(array(
1019+
$connector = new React\Socket\Connector([
10201020
'dns' => $resolver
1021-
));
1021+
]);
10221022

10231023
$connector->connect('localhost:80')->then(function (React\Socket\ConnectionInterface $connection) {
10241024
$connection->write('...');
@@ -1031,18 +1031,18 @@ respects your `default_socket_timeout` ini setting (which defaults to 60s).
10311031
If you want a custom timeout value, you can simply pass this like this:
10321032

10331033
```php
1034-
$connector = new React\Socket\Connector(array(
1034+
$connector = new React\Socket\Connector([
10351035
'timeout' => 10.0
1036-
));
1036+
]);
10371037
```
10381038

10391039
Similarly, if you do not want to apply a timeout at all and let the operating
10401040
system handle this, you can pass a boolean flag like this:
10411041

10421042
```php
1043-
$connector = new React\Socket\Connector(array(
1043+
$connector = new React\Socket\Connector([
10441044
'timeout' => false
1045-
));
1045+
]);
10461046
```
10471047

10481048
By default, the `Connector` supports the `tcp://`, `tls://` and `unix://`
@@ -1051,7 +1051,7 @@ pass boolean flags like this:
10511051

10521052
```php
10531053
// only allow secure TLS connections
1054-
$connector = new React\Socket\Connector(array(
1054+
$connector = new React\Socket\Connector([
10551055
'tcp' => false,
10561056
'tls' => true,
10571057
'unix' => false,
@@ -1070,15 +1070,15 @@ pass arrays of context options like this:
10701070

10711071
```php
10721072
// allow insecure TLS connections
1073-
$connector = new React\Socket\Connector(array(
1074-
'tcp' => array(
1073+
$connector = new React\Socket\Connector([
1074+
'tcp' => [
10751075
'bindto' => '192.168.0.1:0'
1076-
),
1077-
'tls' => array(
1076+
],
1077+
'tls' => [
10781078
'verify_peer' => false,
10791079
'verify_peer_name' => false
1080-
),
1081-
));
1080+
],
1081+
]);
10821082

10831083
$connector->connect('tls://localhost:443')->then(function (React\Socket\ConnectionInterface $connection) {
10841084
$connection->write('...');
@@ -1091,11 +1091,11 @@ SSLv2/SSLv3. You can also explicitly choose the TLS version you
10911091
want to negotiate with the remote side:
10921092

10931093
```php
1094-
$connector = new React\Socket\Connector(array(
1095-
'tls' => array(
1094+
$connector = new React\Socket\Connector([
1095+
'tls' => [
10961096
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
1097-
)
1098-
));
1097+
]
1098+
]);
10991099
```
11001100

11011101
> For more details about context options, please refer to the PHP documentation
@@ -1117,14 +1117,14 @@ $tls = new React\Socket\SecureConnector($tcp);
11171117

11181118
$unix = new React\Socket\UnixConnector();
11191119

1120-
$connector = new React\Socket\Connector(array(
1120+
$connector = new React\Socket\Connector([
11211121
'tcp' => $tcp,
11221122
'tls' => $tls,
11231123
'unix' => $unix,
11241124

11251125
'dns' => false,
11261126
'timeout' => false,
1127-
));
1127+
]);
11281128

11291129
$connector->connect('google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
11301130
$connection->write('...');
@@ -1192,9 +1192,9 @@ You can optionally pass additional
11921192
to the constructor like this:
11931193

11941194
```php
1195-
$tcpConnector = new React\Socket\TcpConnector(null, array(
1195+
$tcpConnector = new React\Socket\TcpConnector(null, [
11961196
'bindto' => '192.168.0.1:0'
1197-
));
1197+
]);
11981198
```
11991199

12001200
Note that this class only allows you to connect to IP-port-combinations.
@@ -1363,20 +1363,20 @@ You can optionally pass additional
13631363
to the constructor like this:
13641364

13651365
```php
1366-
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, array(
1366+
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, [
13671367
'verify_peer' => false,
13681368
'verify_peer_name' => false
1369-
));
1369+
]);
13701370
```
13711371

13721372
By default, this connector supports TLSv1.0+ and excludes support for legacy
13731373
SSLv2/SSLv3. You can also explicitly choose the TLS version you
13741374
want to negotiate with the remote side:
13751375

13761376
```php
1377-
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, array(
1377+
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, [
13781378
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
1379-
));
1379+
]);
13801380
```
13811381

13821382
> Advanced usage: Internally, the `SecureConnector` relies on setting up the

examples/01-echo-server.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323

2424
require __DIR__ . '/../vendor/autoload.php';
2525

26-
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '127.0.0.1:0', array(
27-
'tls' => array(
28-
'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem')
29-
)
30-
));
26+
$socket = new React\Socket\SocketServer($argv[1] ?? '127.0.0.1:0', [
27+
'tls' => [
28+
'local_cert' => $argv[2] ?? __DIR__ . '/localhost.pem'
29+
]
30+
]);
3131

3232
$socket->on('connection', function (React\Socket\ConnectionInterface $connection) {
3333
echo '[' . $connection->getRemoteAddress() . ' connected]' . PHP_EOL;

examples/02-chat-server.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323

2424
require __DIR__ . '/../vendor/autoload.php';
2525

26-
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '127.0.0.1:0', array(
27-
'tls' => array(
28-
'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem')
29-
)
30-
));
26+
$socket = new React\Socket\SocketServer($argv[1] ?? '127.0.0.1:0', [
27+
'tls' => [
28+
'local_cert' => $argv[2] ?? __DIR__ . '/localhost.pem'
29+
]
30+
]);
3131

3232
$socket = new React\Socket\LimitingServer($socket, null);
3333

examples/03-http-server.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838

3939
require __DIR__ . '/../vendor/autoload.php';
4040

41-
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '127.0.0.1:0', array(
42-
'tls' => array(
43-
'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem')
44-
)
45-
));
41+
$socket = new React\Socket\SocketServer($argv[1] ?? '127.0.0.1:0', [
42+
'tls' => [
43+
'local_cert' => $argv[2] ?? __DIR__ . '/localhost.pem'
44+
]
45+
]);
4646

4747
$socket->on('connection', function (React\Socket\ConnectionInterface $connection) {
4848
echo '[' . $connection->getRemoteAddress() . ' connected]' . PHP_EOL;
@@ -61,4 +61,4 @@
6161
echo 'Error: ' . $e->getMessage() . PHP_EOL;
6262
});
6363

64-
echo 'Listening on ' . strtr($socket->getAddress(), array('tcp:' => 'http:', 'tls:' => 'https:')) . PHP_EOL;
64+
echo 'Listening on ' . strtr($socket->getAddress(), ['tcp:' => 'http:', 'tls:' => 'https:']) . PHP_EOL;

examples/11-http-client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use React\Socket\Connector;
1515
use React\Socket\ConnectionInterface;
1616

17-
$host = isset($argv[1]) ? $argv[1] : 'www.google.com';
17+
$host = $argv[1] ?? 'www.google.com';
1818

1919
require __DIR__ . '/../vendor/autoload.php';
2020

examples/12-https-client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use React\Socket\Connector;
1515
use React\Socket\ConnectionInterface;
1616

17-
$host = isset($argv[1]) ? $argv[1] : 'www.google.com';
17+
$host = $argv[1] ?? 'www.google.com';
1818

1919
require __DIR__ . '/../vendor/autoload.php';
2020

examples/22-http-client.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
require __DIR__ . '/../vendor/autoload.php';
2121

22-
$uri = isset($argv[1]) ? $argv[1] : 'www.google.com';
22+
$uri = $argv[1] ?? 'www.google.com';
2323

2424
if (strpos($uri, '://') === false) {
2525
$uri = 'http://' . $uri;
@@ -42,7 +42,7 @@
4242
$host .= ':' . $parts['port'];
4343
}
4444
$target = ($parts['scheme'] === 'https' ? 'tls' : 'tcp') . '://' . $parts['host'] . ':' . $parts['port'];
45-
$resource = isset($parts['path']) ? $parts['path'] : '/';
45+
$resource = $parts['path'] ?? '/';
4646
if (isset($parts['query'])) {
4747
$resource .= '?' . $parts['query'];
4848
}

0 commit comments

Comments
 (0)