@@ -144,12 +144,12 @@ Most importantly, this project provides a [`Browser`](#browser) object that
144144offers several methods that resemble the HTTP protocol methods:
145145
146146``` php
147- $browser->get($url, array $headers = array() );
148- $browser->head($url, array $headers = array() );
149- $browser->post($url, array $headers = array() , string|ReadableStreamInterface $body = '');
150- $browser->delete($url, array $headers = array() , string|ReadableStreamInterface $body = '');
151- $browser->put($url, array $headers = array() , string|ReadableStreamInterface $body = '');
152- $browser->patch($url, array $headers = array() , string|ReadableStreamInterface $body = '');
147+ $browser->get($url, array $headers = [] );
148+ $browser->head($url, array $headers = [] );
149+ $browser->post($url, array $headers = [] , string|ReadableStreamInterface $body = '');
150+ $browser->delete($url, array $headers = [] , string|ReadableStreamInterface $body = '');
151+ $browser->put($url, array $headers = [] , string|ReadableStreamInterface $body = '');
152+ $browser->patch($url, array $headers = [] , string|ReadableStreamInterface $body = '');
153153```
154154
155155Each of these methods requires a ` $url ` and some optional parameters to send an
@@ -285,9 +285,9 @@ like this:
285285``` php
286286$browser = new React\Http\Browser(
287287 new React\Socket\Connector(
288- array(
288+ [
289289 'timeout' => 5
290- )
290+ ]
291291 )
292292);
293293```
@@ -323,9 +323,9 @@ $token = 'abc123';
323323
324324$promise = $browser->get(
325325 'https://example.com/api',
326- array(
326+ [
327327 'Authorization' => 'Bearer ' . $token
328- )
328+ ]
329329);
330330```
331331
@@ -411,10 +411,10 @@ Similarly, you can also process multiple requests concurrently and await an arra
411411use function React\Async\await;
412412use function React\Promise\all;
413413
414- $promises = array(
414+ $promises = [
415415 $browser->get('http://example.com/'),
416416 $browser->get('http://www.example.org/'),
417- ) ;
417+ ] ;
418418
419419$responses = await(all($promises));
420420```
@@ -540,7 +540,7 @@ You can invoke the following methods on the message body:
540540$body->on($event, $callback);
541541$body->eof();
542542$body->isReadable();
543- $body->pipe(React\Stream\WritableStreamInterface $dest, array $options = array() );
543+ $body->pipe(React\Stream\WritableStreamInterface $dest, array $options = [] );
544544$body->close();
545545$body->pause();
546546$body->resume();
@@ -575,10 +575,10 @@ Consider looking into also using [react/promise-stream](https://github.com/react
575575The resulting streaming code could look something like this:
576576
577577``` php
578- use React\Promise\Stream;
578+ use function React\Promise\Stream\unwrapReadable ;
579579
580580function download(Browser $browser, string $url): React\Stream\ReadableStreamInterface {
581- return Stream\ unwrapReadable(
581+ return unwrapReadable(
582582 $browser->requestStreaming('GET', $url)->then(function (Psr\Http\Message\ResponseInterface $response) {
583583 return $response->getBody();
584584 })
@@ -606,7 +606,7 @@ implementing [ReactPHP's `ReadableStreamInterface`](https://github.com/reactphp/
606606to the [ request methods] ( #request-methods ) like this:
607607
608608``` php
609- $browser->post($url, array() , $stream)->then(function (Psr\Http\Message\ResponseInterface $response) {
609+ $browser->post($url, [] , $stream)->then(function (Psr\Http\Message\ResponseInterface $response) {
610610 echo 'Successfully sent.';
611611}, function (Exception $e) {
612612 echo 'Error: ' . $e->getMessage() . PHP_EOL;
@@ -623,7 +623,7 @@ Loop::addTimer(1.0, function () use ($body) {
623623 $body->end("hello world");
624624});
625625
626- $browser->post($url, array( 'Content-Length' => '11') , $body);
626+ $browser->post($url, [ 'Content-Length' => '11'] , $body);
627627```
628628
629629If the streaming request body emits an ` error ` event or is explicitly closed
@@ -645,10 +645,10 @@ protocol, such as plain HTTP and TLS-encrypted HTTPS.
645645``` php
646646$proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
647647
648- $connector = new React\Socket\Connector(array(
648+ $connector = new React\Socket\Connector([
649649 'tcp' => $proxy,
650650 'dns' => false
651- ) );
651+ ] );
652652
653653$browser = new React\Http\Browser($connector);
654654```
@@ -669,10 +669,10 @@ only, this can technically be used to tunnel any TCP/IP-based protocol.
669669``` php
670670$proxy = new Clue\React\Socks\Client('127.0.0.1:1080');
671671
672- $connector = new React\Socket\Connector(array(
672+ $connector = new React\Socket\Connector([
673673 'tcp' => $proxy,
674674 'dns' => false
675- ) );
675+ ] );
676676
677677$browser = new React\Http\Browser($connector);
678678```
@@ -698,10 +698,10 @@ plain HTTP and TLS-encrypted HTTPS.
698698``` php
699699$proxy = new Clue\React\SshProxy\SshSocksConnector('
[email protected] ');
700700
701- $connector = new React\Socket\Connector(array(
701+ $connector = new React\Socket\Connector([
702702 'tcp' => $proxy,
703703 'dns' => false
704- ) );
704+ ] );
705705
706706$browser = new React\Http\Browser($connector);
707707```
@@ -931,11 +931,11 @@ using a secure TLS listen address, a certificate file and optional
931931``` php
932932$http = new React\Http\HttpServer($handler);
933933
934- $socket = new React\Socket\SocketServer('tls://0.0.0.0:8443', array(
935- 'tls' => array(
934+ $socket = new React\Socket\SocketServer('tls://0.0.0.0:8443', [
935+ 'tls' => [
936936 'local_cert' => __DIR__ . '/localhost.pem'
937- )
938- ) );
937+ ]
938+ ] );
939939$http->listen($socket);
940940```
941941
@@ -1456,9 +1456,9 @@ $http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterf
14561456
14571457 return new React\Http\Message\Response(
14581458 React\Http\Message\Response::STATUS_OK,
1459- array(
1459+ [
14601460 'Content-Type' => 'text/plain'
1461- ) ,
1461+ ] ,
14621462 $stream
14631463 );
14641464});
@@ -1558,10 +1558,10 @@ $http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterf
15581558
15591559 return new React\Http\Message\Response(
15601560 React\Http\Message\Response::STATUS_OK,
1561- array(
1561+ [
15621562 'Content-Length' => '13',
15631563 'Content-Type' => 'text/plain',
1564- ) ,
1564+ ] ,
15651565 $stream
15661566 );
15671567});
@@ -1628,9 +1628,9 @@ a custom `Server` response header like this:
16281628$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
16291629 return new React\Http\Message\Response(
16301630 React\Http\Message\Response::STATUS_OK,
1631- array(
1631+ [
16321632 'Server' => 'PHP/3'
1633- )
1633+ ]
16341634 );
16351635});
16361636```
@@ -1643,9 +1643,9 @@ string value like this:
16431643$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
16441644 return new React\Http\Message\Response(
16451645 React\Http\Message\Response::STATUS_OK,
1646- array(
1646+ [
16471647 'Server' => ''
1648- )
1648+ ]
16491649 );
16501650});
16511651```
@@ -1658,9 +1658,9 @@ like this:
16581658$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
16591659 return new React\Http\Message\Response(
16601660 React\Http\Message\Response::STATUS_OK,
1661- array(
1661+ [
16621662 'Date' => gmdate('D, d M Y H:i:s \G\M\T')
1663- )
1663+ ]
16641664 );
16651665});
16661666```
@@ -1673,9 +1673,9 @@ like this:
16731673$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
16741674 return new React\Http\Message\Response(
16751675 React\Http\Message\Response::STATUS_OK,
1676- array(
1676+ [
16771677 'Date' => ''
1678- )
1678+ ]
16791679 );
16801680});
16811681```
@@ -1871,16 +1871,16 @@ proxy servers etc.), you can explicitly pass a custom instance of the
18711871[ ` ConnectorInterface ` ] ( https://github.com/reactphp/socket#connectorinterface ) :
18721872
18731873``` php
1874- $connector = new React\Socket\Connector(array(
1874+ $connector = new React\Socket\Connector([
18751875 'dns' => '127.0.0.1',
1876- 'tcp' => array(
1876+ 'tcp' => [
18771877 'bindto' => '192.168.10.1:0'
1878- ) ,
1879- 'tls' => array(
1878+ ] ,
1879+ 'tls' => [
18801880 'verify_peer' => false,
18811881 'verify_peer_name' => false
1882- )
1883- ) );
1882+ ]
1883+ ] );
18841884
18851885$browser = new React\Http\Browser($connector);
18861886```
@@ -1895,7 +1895,7 @@ given event loop instance.
18951895
18961896#### get()
18971897
1898- The ` get(string $url, array $headers = array() ): PromiseInterface<ResponseInterface> ` method can be used to
1898+ The ` get(string $url, array $headers = [] ): PromiseInterface<ResponseInterface> ` method can be used to
18991899send an HTTP GET request.
19001900
19011901``` php
@@ -1910,7 +1910,7 @@ See also [GET request client example](examples/01-client-get-request.php).
19101910
19111911#### post()
19121912
1913- The ` post(string $url, array $headers = array() , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
1913+ The ` post(string $url, array $headers = [] , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
19141914send an HTTP POST request.
19151915
19161916``` php
@@ -1958,12 +1958,12 @@ Loop::addTimer(1.0, function () use ($body) {
19581958 $body->end("hello world");
19591959});
19601960
1961- $browser->post($url, array( 'Content-Length' => '11'), $body);
1961+ $browser->post($url, [ 'Content-Length' => '11'), $body);
19621962```
19631963
19641964#### head()
19651965
1966- The ` head(string $url, array $headers = array() ): PromiseInterface<ResponseInterface> ` method can be used to
1966+ The ` head(string $url, array $headers = [] ): PromiseInterface<ResponseInterface> ` method can be used to
19671967send an HTTP HEAD request.
19681968
19691969``` php
@@ -1976,7 +1976,7 @@ $browser->head($url)->then(function (Psr\Http\Message\ResponseInterface $respons
19761976
19771977#### patch()
19781978
1979- The ` patch(string $url, array $headers = array() , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
1979+ The ` patch(string $url, array $headers = [] , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
19801980send an HTTP PATCH request.
19811981
19821982``` php
@@ -2005,12 +2005,12 @@ Loop::addTimer(1.0, function () use ($body) {
20052005 $body->end("hello world");
20062006});
20072007
2008- $browser->patch($url, array( 'Content-Length' => '11') , $body);
2008+ $browser->patch($url, [ 'Content-Length' => '11'] , $body);
20092009```
20102010
20112011#### put()
20122012
2013- The ` put(string $url, array $headers = array() , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
2013+ The ` put(string $url, array $headers = [] , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
20142014send an HTTP PUT request.
20152015
20162016``` php
@@ -2041,12 +2041,12 @@ Loop::addTimer(1.0, function () use ($body) {
20412041 $body->end("hello world");
20422042});
20432043
2044- $browser->put($url, array( 'Content-Length' => '11') , $body);
2044+ $browser->put($url, [ 'Content-Length' => '11'] , $body);
20452045```
20462046
20472047#### delete()
20482048
2049- The ` delete(string $url, array $headers = array() , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
2049+ The ` delete(string $url, array $headers = [] , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
20502050send an HTTP DELETE request.
20512051
20522052``` php
@@ -2059,7 +2059,7 @@ $browser->delete($url)->then(function (Psr\Http\Message\ResponseInterface $respo
20592059
20602060#### request()
20612061
2062- The ` request(string $method, string $url, array $headers = array() , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
2062+ The ` request(string $method, string $url, array $headers = [] , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
20632063send an arbitrary HTTP request.
20642064
20652065The preferred way to send an HTTP request is by using the above
@@ -2093,12 +2093,12 @@ Loop::addTimer(1.0, function () use ($body) {
20932093 $body->end("hello world");
20942094});
20952095
2096- $browser->request('POST', $url, array( 'Content-Length' => '11') , $body);
2096+ $browser->request('POST', $url, [ 'Content-Length' => '11'] , $body);
20972097```
20982098
20992099#### requestStreaming()
21002100
2101- The ` requestStreaming(string $method, string $url, array $headers = array() , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
2101+ The ` requestStreaming(string $method, string $url, array $headers = [] , string|ReadableStreamInterface $body = ''): PromiseInterface<ResponseInterface> ` method can be used to
21022102send an arbitrary HTTP request and receive a streaming response without buffering the response body.
21032103
21042104The preferred way to send an HTTP request is by using the above
@@ -2157,7 +2157,7 @@ Loop::addTimer(1.0, function () use ($body) {
21572157 $body->end("hello world");
21582158});
21592159
2160- $browser->requestStreaming('POST', $url, array( 'Content-Length' => '11') , $body);
2160+ $browser->requestStreaming('POST', $url, [ 'Content-Length' => '11'] , $body);
21612161```
21622162
21632163#### withTimeout()
@@ -2428,9 +2428,9 @@ represent an outgoing server response message.
24282428``` php
24292429$response = new React\Http\Message\Response(
24302430 React\Http\Message\Response::STATUS_OK,
2431- array(
2431+ [
24322432 'Content-Type' => 'text/html'
2433- ) ,
2433+ ] ,
24342434 "<html >Hello world!</html >\n"
24352435);
24362436```
@@ -2528,10 +2528,9 @@ values in the data must be encoded in UTF-8 (Unicode). If the encoding
25282528fails, this method will throw an ` InvalidArgumentException ` .
25292529
25302530By default, the given structured data will be encoded with the flags as
2531- shown above. This includes pretty printing (PHP 5.4+) and preserving
2532- zero fractions for ` float ` values (PHP 5.6.6+) to ease debugging. It is
2533- assumed any additional data overhead is usually compensated by using HTTP
2534- response compression.
2531+ shown above. This includes pretty printing and preserving zero fractions
2532+ for ` float ` values to ease debugging. It is assumed any additional data
2533+ overhead is usually compensated by using HTTP response compression.
25352534
25362535If you want to use a different status code or custom HTTP response
25372536headers, you can manipulate the returned response object using the
@@ -2900,9 +2899,9 @@ $handler = function (Psr\Http\Message\ServerRequestInterface $request) {
29002899
29012900 return new React\Http\Message\Response(
29022901 React\Http\Message\Response::STATUS_OK,
2903- array(
2902+ [
29042903 'Content-Type' => 'text/plain'
2905- ) ,
2904+ ] ,
29062905 $name . ' uploaded ' . $uploaded
29072906 );
29082907};
0 commit comments