Skip to content

Commit e85b781

Browse files
authored
Merge pull request #118 from clue-labs/internal
Mark internal APIs as internal or private
2 parents 07f0c43 + 5f86430 commit e85b781

6 files changed

Lines changed: 123 additions & 5 deletions

File tree

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $loop = React\EventLoop\Factory::create();
2525
$socket = new React\Socket\Server(8080, $loop);
2626

2727
$http = new React\Http\Server($socket);
28-
$http->on('request', function ($request, $response) {
28+
$http->on('request', function (Request $request, Response $response) {
2929
$response->writeHead(200, array('Content-Type' => 'text/plain'));
3030
$response->end("Hello World!\n");
3131
});
@@ -39,7 +39,30 @@ See also the [examples](examples).
3939

4040
### Server
4141

42-
See the above usage example and the class outline for details.
42+
The `Server` class is responsible for handling incoming connections and then
43+
emit a `request` event for each incoming HTTP request.
44+
45+
It attaches itself to an instance of `React\Socket\ServerInterface` which
46+
emits underlying streaming connections in order to then parse incoming data
47+
as HTTP:
48+
49+
```php
50+
$socket = new React\Socket\Server(8080, $loop);
51+
52+
$http = new React\Http\Server($socket);
53+
```
54+
55+
For each incoming connection, it emits a `request` event with the respective
56+
[`Request`](#request) and [`Response`](#response) objects:
57+
58+
```php
59+
$http->on('request', function (Request $request, Response $response) {
60+
$response->writeHead(200, array('Content-Type' => 'text/plain'));
61+
$response->end("Hello World!\n");
62+
});
63+
```
64+
65+
See also [`Request`](#request) and [`Response`](#response) for more details.
4366

4467
### Request
4568

@@ -48,6 +71,9 @@ and contains meta data which was parsed from the request headers.
4871

4972
It implements the `ReadableStreamInterface`.
5073

74+
The constructor is internal, you SHOULD NOT call this yourself.
75+
The `Server` is responsible for emitting `Request` and `Response` objects.
76+
5177
See the above usage example and the class outline for details.
5278

5379
#### getMethod()
@@ -116,6 +142,9 @@ The `Response` class is responsible for streaming the outgoing response body.
116142

117143
It implements the `WritableStreamInterface`.
118144

145+
The constructor is internal, you SHOULD NOT call this yourself.
146+
The `Server` is responsible for emitting `Request` and `Response` objects.
147+
119148
See the above usage example and the class outline for details.
120149

121150
#### writeContinue()

src/Request.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
use React\Stream\WritableStreamInterface;
88
use React\Stream\Util;
99

10+
/**
11+
* The `Request` class is responsible for streaming the incoming request body
12+
* and contains meta data which was parsed from the request headers.
13+
*
14+
* It implements the `ReadableStreamInterface`.
15+
*
16+
* The constructor is internal, you SHOULD NOT call this yourself.
17+
* The `Server` is responsible for emitting `Request` and `Response` objects.
18+
*
19+
* See the usage examples and the class outline for details.
20+
*
21+
* @see ReadableStreamInterface
22+
* @see Server
23+
*/
1024
class Request extends EventEmitter implements ReadableStreamInterface
1125
{
1226
private $readable = true;
@@ -19,6 +33,15 @@ class Request extends EventEmitter implements ReadableStreamInterface
1933
// metadata, implicitly added externally
2034
public $remoteAddress;
2135

36+
/**
37+
* The constructor is internal, you SHOULD NOT call this yourself.
38+
*
39+
* The `Server` is responsible for emitting `Request` and `Response` objects.
40+
*
41+
* Constructor parameters may change at any time.
42+
*
43+
* @internal
44+
*/
2245
public function __construct($method, $path, $query = array(), $httpVersion = '1.1', $headers = array())
2346
{
2447
$this->method = $method;

src/RequestHeaderParser.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/**
1010
* @event headers
1111
* @event error
12+
*
13+
* @internal
1214
*/
1315
class RequestHeaderParser extends EventEmitter
1416
{
@@ -43,13 +45,13 @@ public function feed($data)
4345
}
4446
}
4547

46-
protected function parseAndEmitRequest()
48+
private function parseAndEmitRequest()
4749
{
4850
list($request, $bodyBuffer) = $this->parseRequest($this->buffer);
4951
$this->emit('headers', array($request, $bodyBuffer));
5052
}
5153

52-
public function parseRequest($data)
54+
private function parseRequest($data)
5355
{
5456
list($headers, $bodyBuffer) = explode("\r\n\r\n", $data, 2);
5557

src/Response.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
use React\Socket\ConnectionInterface;
77
use React\Stream\WritableStreamInterface;
88

9+
/**
10+
* The `Response` class is responsible for streaming the outgoing response body.
11+
*
12+
* It implements the `WritableStreamInterface`.
13+
*
14+
* The constructor is internal, you SHOULD NOT call this yourself.
15+
* The `Server` is responsible for emitting `Request` and `Response` objects.
16+
*
17+
* See the usage examples and the class outline for details.
18+
*
19+
* @see WritableStreamInterface
20+
* @see Server
21+
*/
922
class Response extends EventEmitter implements WritableStreamInterface
1023
{
1124
private $closed = false;
@@ -14,6 +27,15 @@ class Response extends EventEmitter implements WritableStreamInterface
1427
private $headWritten = false;
1528
private $chunkedEncoding = true;
1629

30+
/**
31+
* The constructor is internal, you SHOULD NOT call this yourself.
32+
*
33+
* The `Server` is responsible for emitting `Request` and `Response` objects.
34+
*
35+
* Constructor parameters may change at any time.
36+
*
37+
* @internal
38+
*/
1739
public function __construct(ConnectionInterface $conn)
1840
{
1941
$this->conn = $conn;

src/ResponseCodes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
/**
66
* This is copy-pasted from Symfony2's Response class
7+
*
8+
* @internal
79
*/
810
class ResponseCodes
911
{

src/Server.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,50 @@
66
use React\Socket\ServerInterface as SocketServerInterface;
77
use React\Socket\ConnectionInterface;
88

9-
/** @event request */
9+
/**
10+
* The `Server` class is responsible for handling incoming connections and then
11+
* emit a `request` event for each incoming HTTP request.
12+
*
13+
* ```php
14+
* $socket = new React\Socket\Server(8080, $loop);
15+
*
16+
* $http = new React\Http\Server($socket);
17+
* ```
18+
*
19+
* For each incoming connection, it emits a `request` event with the respective
20+
* [`Request`](#request) and [`Response`](#response) objects:
21+
*
22+
* ```php
23+
* $http->on('request', function (Request $request, Response $response) {
24+
* $response->writeHead(200, array('Content-Type' => 'text/plain'));
25+
* $response->end("Hello World!\n");
26+
* });
27+
* ```
28+
*
29+
* See also [`Request`](#request) and [`Response`](#response) for more details.
30+
*
31+
* @see Request
32+
* @see Response
33+
*/
1034
class Server extends EventEmitter
1135
{
1236
private $io;
1337

38+
/**
39+
* Creates a HTTP server that accepts connections from the given socket.
40+
*
41+
* It attaches itself to an instance of `React\Socket\ServerInterface` which
42+
* emits underlying streaming connections in order to then parse incoming data
43+
* as HTTP:
44+
*
45+
* ```php
46+
* $socket = new React\Socket\Server(8080, $loop);
47+
*
48+
* $http = new React\Http\Server($socket);
49+
* ```
50+
*
51+
* @param \React\Socket\ServerInterface $io
52+
*/
1453
public function __construct(SocketServerInterface $io)
1554
{
1655
$this->io = $io;
@@ -54,6 +93,7 @@ public function __construct(SocketServerInterface $io)
5493
});
5594
}
5695

96+
/** @internal */
5797
public function handleRequest(ConnectionInterface $conn, Request $request, $bodyBuffer)
5898
{
5999
$response = new Response($conn);

0 commit comments

Comments
 (0)