Skip to content

Commit 84b4923

Browse files
committed
Update docs
1 parent 020a3de commit 84b4923

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ are always welcome!
2020

2121
## Requirements
2222

23-
- PHP 7.1+
23+
- PHP 7.2+
2424

2525
## Example
2626

@@ -32,16 +32,16 @@ are always welcome!
3232
// amphp/http-server-static-content
3333
// amphp/log
3434

35+
use Amp\Http\Server\HttpServer;
3536
use Amp\Http\Server\Request;
3637
use Amp\Http\Server\Response;
3738
use Amp\Http\Server\Router;
38-
use Amp\Http\Server\Server;
3939
use Amp\Http\Server\StaticContent\DocumentRoot;
4040
use Amp\Log\ConsoleFormatter;
4141
use Amp\Log\StreamHandler;
4242
use Amp\Loop;
4343
use Amp\Promise;
44-
use Amp\Socket;
44+
use Amp\Socket\Server as SocketServer;
4545
use Amp\Success;
4646
use Amp\Websocket\Client;
4747
use Amp\Websocket\Message;
@@ -64,7 +64,7 @@ $websocket = new class extends Websocket {
6464

6565
public function handleClient(Client $client, Request $request, Response $response): Promise
6666
{
67-
return call(function() use($client) {
67+
return call(function() use ($client): \Generator {
6868
while ($message = yield $client->receive()) {
6969
\assert($message instanceof Message);
7070
$this->broadcast(\sprintf('%d: %s', $client->getId(), yield $message->buffer()));
@@ -73,23 +73,23 @@ $websocket = new class extends Websocket {
7373
}
7474
};
7575

76-
$sockets = [
77-
Socket\listen('127.0.0.1:1337'),
78-
Socket\listen('[::1]:1337'),
79-
];
76+
Loop::run(function () use ($websocket): Promise {
77+
$sockets = [
78+
SocketServer::listen('127.0.0.1:1337'),
79+
SocketServer::listen('[::1]:1337'),
80+
];
8081

81-
$router = new Router;
82-
$router->addRoute('GET', '/broadcast', $websocket);
83-
$router->setFallback(new DocumentRoot(__DIR__ . '/public'));
82+
$router = new Router;
83+
$router->addRoute('GET', '/broadcast', $websocket);
84+
$router->setFallback(new DocumentRoot(__DIR__ . '/public'));
8485

85-
$logHandler = new StreamHandler(getStdout());
86-
$logHandler->setFormatter(new ConsoleFormatter);
87-
$logger = new Logger('server');
88-
$logger->pushHandler($logHandler);
86+
$logHandler = new StreamHandler(getStdout());
87+
$logHandler->setFormatter(new ConsoleFormatter);
88+
$logger = new Logger('server');
89+
$logger->pushHandler($logHandler);
8990

90-
$server = new Server($sockets, $router, $logger);
91+
$server = new HttpServer($sockets, $router, $logger);
9192

92-
Loop::run(function () use ($server) {
93-
yield $server->start();
93+
return $server->start();
9494
});
9595
```

src/ClientHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public function handleHandshake(Request $request, Response $response): Promise;
5151
/**
5252
* This method is called when a new websocket connection is established on the endpoint.
5353
* The method may handle all messages itself or pass the connection along to a separate
54-
* handler if desired.
54+
* handler if desired. The client connection is closed when the promise returned from
55+
* this method resolves.
5556
*
5657
* ```
5758
* return Amp\call(function () use ($client) {

src/Websocket.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ public function getOptions(): Options
362362
* Invoked when the server is starting.
363363
* Server sockets have been opened, but are not yet accepting client connections. This method should be used to set
364364
* up any necessary state for responding to requests, including starting loop watchers such as timers.
365-
* Note: Implementations overriding this method must always call the parent method.
366365
*
367366
* @param Server $server
368367
*
@@ -385,7 +384,6 @@ public function onStart(Server $server): Promise
385384
* Invoked when the server has initiated stopping.
386385
* No further requests are accepted and any connected clients should be closed gracefully and any loop watchers
387386
* cancelled.
388-
* Note: Implementations overriding this method must always call the parent method.
389387
*
390388
* @param Server $server
391389
*

0 commit comments

Comments
 (0)