Skip to content

Commit e8633d7

Browse files
committed
Documentation for internal APIs
1 parent dea9c00 commit e8633d7

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/Io/ResponseParser.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,46 @@
44

55
use Psr\Http\Message\ResponseInterface;
66

7+
/**
8+
* ResponseParser is a simple helper to return the buffered body of HTTP response objects
9+
*
10+
* @internal
11+
* @see StreamingParser for working with streaming bodies
12+
*/
713
class ResponseParser
814
{
15+
/**
16+
* Returns the plain text body of the given $response
17+
*
18+
* @param ResponseInterface $response
19+
* @return string
20+
*/
921
public function expectPlain(ResponseInterface $response)
1022
{
1123
// text/plain
1224

1325
return (string)$response->getBody();
1426
}
1527

28+
/**
29+
* Returns the parsed JSON body of the given $response
30+
*
31+
* @param ResponseInterface $response
32+
* @return array
33+
*/
1634
public function expectJson(ResponseInterface $response)
1735
{
1836
// application/json
1937

2038
return json_decode((string)$response->getBody(), true);
2139
}
2240

41+
/**
42+
* Returns the empty plain text body of the given $response
43+
*
44+
* @param ResponseInterface $response
45+
* @return string
46+
*/
2347
public function expectEmpty(ResponseInterface $response)
2448
{
2549
// 204 No Content

src/Io/StreamingParser.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,21 @@
1212
use Clue\React\Promise\Stream;
1313
use Psr\Http\Message\ResponseInterface;
1414

15+
/**
16+
* StreamingParser is a simple helper to work with the streaming body of HTTP response objects
17+
*
18+
* @internal
19+
* @see ResponseParser for working with buffered bodies
20+
*/
1521
class StreamingParser
1622
{
23+
/**
24+
* Returns a readable JSON stream for the given ResponseInterface
25+
*
26+
* @param PromiseInterface $promise Promise<ResponseInterface>
27+
* @return ReadableStreamInterface
28+
* @uses self::parsePlainSream()
29+
*/
1730
public function parseJsonStream(PromiseInterface $promise)
1831
{
1932
// application/json
@@ -56,6 +69,12 @@ public function parseJsonStream(PromiseInterface $promise)
5669
return $out;
5770
}
5871

72+
/**
73+
* Returns a readable plain text stream for the given ResponseInterface
74+
*
75+
* @param PromiseInterface $promise Promise<ResponseInterface>
76+
* @return ReadableStreamInterface
77+
*/
5978
public function parsePlainStream(PromiseInterface $promise)
6079
{
6180
// text/plain
@@ -65,6 +84,13 @@ public function parsePlainStream(PromiseInterface $promise)
6584
}));
6685
}
6786

87+
/**
88+
* Returns a promise which resolves with an array of all "progress" events
89+
*
90+
* @param ReadableStreamInterface $stream
91+
* @param string $progressEventName the name of the event to collect
92+
* @return PromiseInterface Promise<array, Exception>
93+
*/
6894
public function deferredStream(ReadableStreamInterface $stream, $progressEventName)
6995
{
7096
// cancelling the deferred will (try to) close the stream

0 commit comments

Comments
 (0)