Skip to content

Commit f3271fa

Browse files
committed
Improve documentation to use fully-qualified function names
1 parent 57b90ea commit f3271fa

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,26 @@ for [ReactPHP](https://reactphp.org/).
2222
This lightweight library consists only of a few simple functions.
2323
All functions reside under the `React\Promise\Stream` namespace.
2424

25-
The below examples assume you use an import statement similar to this:
25+
The below examples assume refer to them with their fully-qualified names like this:
2626

2727
```php
28-
use React\Promise\Stream;
28+
React\Promise\Stream\buffer(…);
29+
```
2930

30-
Stream\buffer(…);
31+
As of PHP 5.6+ you can also import each required function into your code like this:
32+
33+
```php
34+
use function React\Promise\Stream\buffer;
35+
36+
buffer(…);
3137
```
3238

33-
Alternatively, you can also refer to them with their fully-qualified name:
39+
Alternatively, you can also use an import statement similar to this:
3440

3541
```php
36-
\React\Promise\Stream\buffer(…);
42+
use React\Promise\Stream;
43+
44+
Stream\buffer(…);
3745
```
3846

3947
### buffer()
@@ -44,7 +52,7 @@ create a `Promise` which resolves with the stream data buffer.
4452
```php
4553
$stream = accessSomeJsonStream();
4654

47-
Stream\buffer($stream)->then(function ($contents) {
55+
React\Promise\Stream\buffer($stream)->then(function ($contents) {
4856
var_dump(json_decode($contents));
4957
});
5058
```
@@ -64,7 +72,7 @@ will be rejected with an `\OverflowException`.
6472
```php
6573
$stream = accessSomeToLargeStream();
6674

67-
Stream\buffer($stream, 1024)->then(function ($contents) {
75+
React\Promise\Stream\buffer($stream, 1024)->then(function ($contents) {
6876
var_dump(json_decode($contents));
6977
}, function ($error) {
7078
// Reaching here when the stream buffer goes above the max size,
@@ -81,7 +89,7 @@ create a `Promise` which resolves once the given event triggers for the first ti
8189
```php
8290
$stream = accessSomeJsonStream();
8391

84-
Stream\first($stream)->then(function ($chunk) {
92+
React\Promise\Stream\first($stream)->then(function ($chunk) {
8593
echo 'The first chunk arrived: ' . $chunk;
8694
});
8795
```
@@ -109,7 +117,7 @@ create a `Promise` which resolves with an array of all the event data.
109117
```php
110118
$stream = accessSomeJsonStream();
111119

112-
Stream\all($stream)->then(function ($chunks) {
120+
React\Promise\Stream\all($stream)->then(function ($chunks) {
113121
echo 'The stream consists of ' . count($chunks) . ' chunk(s)';
114122
});
115123
```
@@ -141,7 +149,7 @@ be piped to the output stream.
141149
//$promise = someFunctionWhichResolvesWithAStream();
142150
$promise = startDownloadStream($uri);
143151

144-
$stream = Stream\unwrapReadable($promise);
152+
$stream = React\Promise\Stream\unwrapReadable($promise);
145153

146154
$stream->on('data', function ($data) {
147155
echo $data;
@@ -159,7 +167,7 @@ an `error` event and close:
159167
```php
160168
$promise = startDownloadStream($invalidUri);
161169

162-
$stream = Stream\unwrapReadable($promise);
170+
$stream = React\Promise\Stream\unwrapReadable($promise);
163171

164172
$stream->on('error', function (Exception $error) {
165173
echo 'Error: ' . $error->getMessage();
@@ -178,7 +186,7 @@ You can `close()` the resulting stream at any time, which will either try to
178186
```php
179187
$promise = startDownloadStream($uri);
180188

181-
$stream = Stream\unwrapReadable($promise);
189+
$stream = React\Promise\Stream\unwrapReadable($promise);
182190

183191
$loop->addTimer(2.0, function () use ($stream) {
184192
$stream->close();
@@ -200,7 +208,7 @@ have written to the proxy will be forwarded transparently to the inner stream.
200208
//$promise = someFunctionWhichResolvesWithAStream();
201209
$promise = startUploadStream($uri);
202210

203-
$stream = Stream\unwrapWritable($promise);
211+
$stream = React\Promise\Stream\unwrapWritable($promise);
204212

205213
$stream->write('hello');
206214
$stream->end('world');
@@ -217,7 +225,7 @@ an `error` event and close:
217225
```php
218226
$promise = startUploadStream($invalidUri);
219227

220-
$stream = Stream\unwrapWritable($promise);
228+
$stream = React\Promise\Stream\unwrapWritable($promise);
221229

222230
$stream->on('error', function (Exception $error) {
223231
echo 'Error: ' . $error->getMessage();
@@ -236,7 +244,7 @@ You can `close()` the resulting stream at any time, which will either try to
236244
```php
237245
$promise = startUploadStream($uri);
238246

239-
$stream = Stream\unwrapWritable($promise);
247+
$stream = React\Promise\Stream\unwrapWritable($promise);
240248

241249
$loop->addTimer(2.0, function () use ($stream) {
242250
$stream->close();

src/functions.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* ```php
1515
* $stream = accessSomeJsonStream();
1616
*
17-
* Stream\buffer($stream)->then(function ($contents) {
17+
* React\Promise\Stream\buffer($stream)->then(function ($contents) {
1818
* var_dump(json_decode($contents));
1919
* });
2020
* ```
@@ -34,7 +34,7 @@
3434
* ```php
3535
* $stream = accessSomeToLargeStream();
3636
*
37-
* Stream\buffer($stream, 1024)->then(function ($contents) {
37+
* React\Promise\Stream\buffer($stream, 1024)->then(function ($contents) {
3838
* var_dump(json_decode($contents));
3939
* }, function ($error) {
4040
* // Reaching here when the stream buffer goes above the max size,
@@ -97,7 +97,7 @@ function buffer(ReadableStreamInterface $stream, $maxLength = null)
9797
* ```php
9898
* $stream = accessSomeJsonStream();
9999
*
100-
* Stream\first($stream)->then(function ($chunk) {
100+
* React\Promise\Stream\first($stream)->then(function ($chunk) {
101101
* echo 'The first chunk arrived: ' . $chunk;
102102
* });
103103
* ```
@@ -170,7 +170,7 @@ function first(EventEmitterInterface $stream, $event = 'data')
170170
* ```php
171171
* $stream = accessSomeJsonStream();
172172
*
173-
* Stream\all($stream)->then(function ($chunks) {
173+
* React\Promise\Stream\all($stream)->then(function ($chunks) {
174174
* echo 'The stream consists of ' . count($chunks) . ' chunk(s)';
175175
* });
176176
* ```
@@ -251,7 +251,7 @@ function all(EventEmitterInterface $stream, $event = 'data')
251251
* //$promise = someFunctionWhichResolvesWithAStream();
252252
* $promise = startDownloadStream($uri);
253253
*
254-
* $stream = Stream\unwrapReadable($promise);
254+
* $stream = React\Promise\Stream\unwrapReadable($promise);
255255
*
256256
* $stream->on('data', function ($data) {
257257
* echo $data;
@@ -269,7 +269,7 @@ function all(EventEmitterInterface $stream, $event = 'data')
269269
* ```php
270270
* $promise = startDownloadStream($invalidUri);
271271
*
272-
* $stream = Stream\unwrapReadable($promise);
272+
* $stream = React\Promise\Stream\unwrapReadable($promise);
273273
*
274274
* $stream->on('error', function (Exception $error) {
275275
* echo 'Error: ' . $error->getMessage();
@@ -288,7 +288,7 @@ function all(EventEmitterInterface $stream, $event = 'data')
288288
* ```php
289289
* $promise = startDownloadStream($uri);
290290
*
291-
* $stream = Stream\unwrapReadable($promise);
291+
* $stream = React\Promise\Stream\unwrapReadable($promise);
292292
*
293293
* $loop->addTimer(2.0, function () use ($stream) {
294294
* $stream->close();
@@ -316,7 +316,7 @@ function unwrapReadable(PromiseInterface $promise)
316316
* //$promise = someFunctionWhichResolvesWithAStream();
317317
* $promise = startUploadStream($uri);
318318
*
319-
* $stream = Stream\unwrapWritable($promise);
319+
* $stream = React\Promise\Stream\unwrapWritable($promise);
320320
*
321321
* $stream->write('hello');
322322
* $stream->end('world');
@@ -333,7 +333,7 @@ function unwrapReadable(PromiseInterface $promise)
333333
* ```php
334334
* $promise = startUploadStream($invalidUri);
335335
*
336-
* $stream = Stream\unwrapWritable($promise);
336+
* $stream = React\Promise\Stream\unwrapWritable($promise);
337337
*
338338
* $stream->on('error', function (Exception $error) {
339339
* echo 'Error: ' . $error->getMessage();
@@ -352,7 +352,7 @@ function unwrapReadable(PromiseInterface $promise)
352352
* ```php
353353
* $promise = startUploadStream($uri);
354354
*
355-
* $stream = Stream\unwrapWritable($promise);
355+
* $stream = React\Promise\Stream\unwrapWritable($promise);
356356
*
357357
* $loop->addTimer(2.0, function () use ($stream) {
358358
* $stream->close();

0 commit comments

Comments
 (0)