Skip to content
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

Simplify usage by supporting new Socket API without nullable loop arguments #419

Merged
merged 1 commit into from
Aug 4, 2021
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
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ $http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterf
);
});

$socket = new React\Socket\Server(8080);
$socket = new React\Socket\SocketServer('127.0.0.1:8080');
$http->listen($socket);
```

Expand Down Expand Up @@ -260,7 +260,6 @@ like this:
```php
$browser = new React\Http\Browser(
new React\Socket\Connector(
null,
array(
'timeout' => 5
)
Expand Down Expand Up @@ -604,7 +603,7 @@ $proxy = new Clue\React\HttpProxy\ProxyConnector(
new React\Socket\Connector()
);

$connector = new React\Socket\Connector(null, array(
$connector = new React\Socket\Connector(array(
'tcp' => $proxy,
'dns' => false
));
Expand All @@ -631,7 +630,7 @@ $proxy = new Clue\React\Socks\Client(
new React\Socket\Connector()
);

$connector = new React\Socket\Connector(null, array(
$connector = new React\Socket\Connector(array(
'tcp' => $proxy,
'dns' => false
));
Expand Down Expand Up @@ -660,7 +659,7 @@ plain HTTP and TLS-encrypted HTTPS.
```php
$proxy = new Clue\React\SshProxy\SshSocksConnector('me@localhost:22', Loop::get());

$connector = new React\Socket\Connector(null, array(
$connector = new React\Socket\Connector(array(
'tcp' => $proxy,
'dns' => false
));
Expand Down Expand Up @@ -741,13 +740,13 @@ to be attached to an instance of
[`React\Socket\ServerInterface`](https://github.com/reactphp/socket#serverinterface)
through the [`listen()`](#listen) method as described in the following
chapter. In its most simple form, you can attach this to a
[`React\Socket\Server`](https://github.com/reactphp/socket#server) in order
to start a plaintext HTTP server like this:
[`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
in order to start a plaintext HTTP server like this:

```php
$http = new React\Http\HttpServer($handler);

$socket = new React\Socket\Server('0.0.0.0:8080');
$socket = new React\Socket\SocketServer('0.0.0.0:8080');
$http->listen($socket);
```

Expand Down Expand Up @@ -869,13 +868,13 @@ is responsible for emitting the underlying streaming connections. This
HTTP server needs to be attached to it in order to process any
connections and pase incoming streaming data as incoming HTTP request
messages. In its most common form, you can attach this to a
[`React\Socket\Server`](https://github.com/reactphp/socket#server) in
order to start a plaintext HTTP server like this:
[`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
in order to start a plaintext HTTP server like this:

```php
$http = new React\Http\HttpServer($handler);

$socket = new React\Socket\Server('0.0.0.0:8080');
$socket = new React\Socket\SocketServer('0.0.0.0:8080');
$http->listen($socket);
```

Expand All @@ -894,15 +893,17 @@ Likewise, it's usually recommended to use a reverse proxy setup to accept
secure HTTPS requests on default HTTPS port `443` (TLS termination) and
only route plaintext requests to this HTTP server. As an alternative, you
can also accept secure HTTPS requests with this HTTP server by attaching
this to a [`React\Socket\Server`](https://github.com/reactphp/socket#server)
this to a [`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
using a secure TLS listen address, a certificate file and optional
`passphrase` like this:

```php
$http = new React\Http\HttpServer($handler);

$socket = new React\Socket\Server('tls://0.0.0.0:8443', null, array(
'local_cert' => __DIR__ . '/localhost.pem'
$socket = new React\Socket\SocketServer('tls://0.0.0.0:8443', array(
'tls' => array(
'local_cert' => __DIR__ . '/localhost.pem'
)
));
$http->listen($socket);
```
Expand Down Expand Up @@ -1889,7 +1890,7 @@ 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(null, array(
$connector = new React\Socket\Connector(array(
'dns' => '127.0.0.1',
'tcp' => array(
'bindto' => '192.168.10.1:0'
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"react/event-loop": "^1.2",
"react/promise": "^2.3 || ^1.2.1",
"react/promise-stream": "^1.1",
"react/socket": "^1.8",
"react/socket": "^1.9",
"react/stream": "^1.2",
"ringcentral/psr7": "^1.2"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/11-client-http-connect-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
$proxy = new HttpConnectClient('127.0.0.1:8080', new Connector());

// create a Browser object that uses the HTTP CONNECT proxy client for connections
$connector = new Connector(null, array(
$connector = new Connector(array(
'tcp' => $proxy,
'dns' => false
));
Expand Down
2 changes: 1 addition & 1 deletion examples/12-client-socks-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$proxy = new SocksClient('127.0.0.1:1080', new Connector());

// create a Browser object that uses the SOCKS proxy client for connections
$connector = new Connector(null, array(
$connector = new Connector(array(
'tcp' => $proxy,
'dns' => false
));
Expand Down
2 changes: 1 addition & 1 deletion examples/13-client-ssh-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$proxy = new SshSocksConnector(isset($argv[1]) ? $argv[1] : 'localhost:22', Loop::get());

// create a Browser object that uses the SSH proxy client for connections
$connector = new Connector(null, array(
$connector = new Connector(array(
'tcp' => $proxy,
'dns' => false
));
Expand Down
2 changes: 1 addition & 1 deletion examples/51-server-hello-world.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/52-server-count-visitors.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/53-server-whatsmyip.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/54-server-query-parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/55-server-cookie-handling.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/56-server-sleep.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
});
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/57-server-error-handling.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
});
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/58-server-stream-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/59-server-json-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
10 changes: 6 additions & 4 deletions examples/61-server-hello-world-https.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SecureServer($socket, null, array(
'local_cert' => isset($argv[2]) ? $argv[2] : __DIR__ . '/localhost.pem'
$uri = 'tls://' . (isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer($uri, array(
'tls' => array(
'local_cert' => isset($argv[2]) ? $argv[2] : __DIR__ . '/localhost.pem'
)
));
$http->listen($socket);

//$socket->on('error', 'printf');
$socket->on('error', 'printf');

echo 'Listening on ' . str_replace('tls:', 'https:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/62-server-form-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
$handler
);

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/63-server-streaming-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function (Psr\Http\Message\ServerRequestInterface $request) {

$http->on('error', 'printf');

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/71-server-http-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/72-server-http-connect-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function ($e) {
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/81-server-upgrade-echo.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/82-server-upgrade-chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/99-server-benchmark-download.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getSize()
);
});

$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
2 changes: 1 addition & 1 deletion src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Browser
* [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface):
*
* ```php
* $connector = new React\Socket\Connector(null, array(
* $connector = new React\Socket\Connector(array(
* 'dns' => '127.0.0.1',
* 'tcp' => array(
* 'bindto' => '192.168.10.1:0'
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Client
public function __construct(LoopInterface $loop, ConnectorInterface $connector = null)
{
if ($connector === null) {
$connector = new Connector($loop);
$connector = new Connector(array(), $loop);
}

$this->connector = $connector;
Expand Down
20 changes: 11 additions & 9 deletions src/HttpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
* [`React\Socket\ServerInterface`](https://github.com/reactphp/socket#serverinterface)
* through the [`listen()`](#listen) method as described in the following
* chapter. In its most simple form, you can attach this to a
* [`React\Socket\Server`](https://github.com/reactphp/socket#server) in order
* to start a plaintext HTTP server like this:
* [`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
* in order to start a plaintext HTTP server like this:
*
* ```php
* $http = new React\Http\HttpServer($handler);
*
* $socket = new React\Socket\Server('0.0.0.0:8080');
* $socket = new React\Socket\SocketServer('0.0.0.0:8080');
* $http->listen($socket);
* ```
*
Expand Down Expand Up @@ -263,13 +263,13 @@ public function __construct($requestHandlerOrLoop)
* HTTP server needs to be attached to it in order to process any
* connections and pase incoming streaming data as incoming HTTP request
* messages. In its most common form, you can attach this to a
* [`React\Socket\Server`](https://github.com/reactphp/socket#server) in
* order to start a plaintext HTTP server like this:
* [`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
* in order to start a plaintext HTTP server like this:
*
* ```php
* $http = new React\Http\HttpServer($handler);
*
* $socket = new React\Socket\Server(8080);
* $socket = new React\Socket\SocketServer('0.0.0.0:8080');
* $http->listen($socket);
* ```
*
Expand All @@ -288,15 +288,17 @@ public function __construct($requestHandlerOrLoop)
* secure HTTPS requests on default HTTPS port `443` (TLS termination) and
* only route plaintext requests to this HTTP server. As an alternative, you
* can also accept secure HTTPS requests with this HTTP server by attaching
* this to a [`React\Socket\Server`](https://github.com/reactphp/socket#server)
* this to a [`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
* using a secure TLS listen address, a certificate file and optional
* `passphrase` like this:
*
* ```php
* $http = new React\Http\HttpServer($handler);
*
* $socket = new React\Socket\Server('tls://0.0.0.0:8443', null, array(
* 'local_cert' => __DIR__ . '/localhost.pem'
* $socket = new React\Socket\SocketServer('tls://0.0.0.0:8443', array(
* 'tls' => array(
* 'local_cert' => __DIR__ . '/localhost.pem'
* )
* ));
* $http->listen($socket);
* ```
Expand Down
2 changes: 1 addition & 1 deletion src/Io/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Sender
* settings. You can use this method manually like this:
*
* ```php
* $connector = new \React\Socket\Connector($loop);
* $connector = new \React\Socket\Connector(array(), $loop);
* $sender = \React\Http\Io\Sender::createFromLoop($loop, $connector);
* ```
*
Expand Down
Loading