@@ -10,10 +10,10 @@ A simple and modern approach to stream filtering in PHP
1010* [ Why?] ( #why )
1111* [ Support us] ( #support-us )
1212* [ Usage] ( #usage )
13- * [ append()] ( #append )
14- * [ prepend()] ( #prepend )
15- * [ fun()] ( #fun )
16- * [ remove()] ( #remove )
13+ * [ append()] ( #append )
14+ * [ prepend()] ( #prepend )
15+ * [ fun()] ( #fun )
16+ * [ remove()] ( #remove )
1717* [ Install] ( #install )
1818* [ Tests] ( #tests )
1919* [ License] ( #license )
@@ -58,26 +58,26 @@ Let's take these projects to the next level together! 🚀
5858This lightweight library consists only of a few simple functions.
5959All functions reside under the ` Clue\StreamFilter ` namespace.
6060
61- The below examples assume you use an import statement similar to this:
61+ The below examples refer to all functions with their fully-qualified names like this:
6262
6363``` php
64- use Clue\StreamFilter as Filter;
65-
66- Filter\append(…);
64+ Clue\StreamFilter\append(…);
6765```
6866
69- Alternatively, you can also refer to them with their fully-qualified name :
67+ As of PHP 5.6+ you can also import each required function into your code like this :
7068
7169``` php
72- \Clue\StreamFilter\append(…);
70+ use function Clue\StreamFilter\append;
71+
72+ append(…);
7373```
7474
75- As of PHP 5.6+ you can also import each required function into your code like this:
75+ Alternatively, you can also use an import statement similar to this:
7676
7777``` php
78- use function Clue\StreamFilter\append ;
78+ use Clue\StreamFilter as Filter ;
7979
80- append(…);
80+ Filter\ append(…);
8181```
8282
8383### append()
@@ -100,7 +100,7 @@ The `$callback` should be a valid callable function which accepts
100100an individual chunk of data and should return the updated chunk:
101101
102102``` php
103- $filter = Filter \append($stream, function ($chunk) {
103+ $filter = Clue\StreamFilter \append($stream, function ($chunk) {
104104 // will be called each time you read or write a $chunk to/from the stream
105105 return $chunk;
106106});
@@ -109,7 +109,7 @@ $filter = Filter\append($stream, function ($chunk) {
109109As such, you can also use native PHP functions or any other ` callable ` :
110110
111111``` php
112- Filter \append($stream, 'strtoupper');
112+ Clue\StreamFilter \append($stream, 'strtoupper');
113113
114114// will write "HELLO" to the underlying stream
115115fwrite($stream, 'hello');
@@ -119,7 +119,7 @@ If the `$callback` accepts invocation without parameters,
119119then this signature will be invoked once ending (flushing) the filter:
120120
121121``` php
122- Filter \append($stream, function ($chunk = null) {
122+ Clue\StreamFilter \append($stream, function ($chunk = null) {
123123 if ($chunk === null) {
124124 // will be called once ending the filter
125125 return 'end';
@@ -139,7 +139,7 @@ In order to play nice with PHP's stream handling,
139139the ` Exception ` will be transformed to a PHP warning instead:
140140
141141``` php
142- Filter \append($stream, function ($chunk) {
142+ Clue\StreamFilter \append($stream, function ($chunk) {
143143 throw new \RuntimeException('Unexpected chunk');
144144});
145145
@@ -151,12 +151,12 @@ The optional `$read_write` parameter can be used to only invoke the `$callback`
151151when either writing to the stream or only when reading from the stream:
152152
153153``` php
154- Filter \append($stream, function ($chunk) {
154+ Clue\StreamFilter \append($stream, function ($chunk) {
155155 // will be called each time you write to the stream
156156 return $chunk;
157157}, STREAM_FILTER_WRITE);
158158
159- Filter \append($stream, function ($chunk) {
159+ Clue\StreamFilter \append($stream, function ($chunk) {
160160 // will be called each time you read from the stream
161161 return $chunk;
162162}, STREAM_FILTER_READ);
@@ -186,7 +186,7 @@ This function prepends a filter to the start of this list.
186186If the given filter can not be added, it throws an ` Exception ` .
187187
188188``` php
189- $filter = Filter \prepend($stream, function ($chunk) {
189+ $filter = Clue\StreamFilter \prepend($stream, function ($chunk) {
190190 // will be called each time you read or write a $chunk to/from the stream
191191 return $chunk;
192192});
@@ -208,7 +208,7 @@ Using `fun()` makes accessing these as easy as passing an input string to filter
208208and getting the filtered output string.
209209
210210``` php
211- $fun = Filter \fun('string.rot13');
211+ $fun = Clue\StreamFilter \fun('string.rot13');
212212
213213assert('grfg' === $fun('test'));
214214assert('test' === $fun($fun('test'));
@@ -221,7 +221,7 @@ or parameters as Zend PHP.
221221Accessing an unknown filter function will result in a ` RuntimeException ` :
222222
223223``` php
224- Filter \fun('unknown'); // throws RuntimeException
224+ Clue\StreamFilter \fun('unknown'); // throws RuntimeException
225225```
226226
227227Some filters may accept or require additional filter parameters – most
@@ -234,7 +234,7 @@ Please refer to the individual filter definition for more details.
234234For example, the ` string.strip_tags ` filter can be invoked like this:
235235
236236``` php
237- $fun = Filter \fun('string.strip_tags', '<a ><b >');
237+ $fun = Clue\StreamFilter \fun('string.strip_tags', '<a ><b >');
238238
239239$ret = $fun('<b >h<br >i</b >');
240240assert('<b >hi</b >' === $ret);
@@ -248,7 +248,7 @@ may use internal buffers and may emit a final data chunk on close.
248248The filter function can be closed by invoking without any arguments:
249249
250250``` php
251- $fun = Filter \fun('zlib.deflate');
251+ $fun = Clue\StreamFilter \fun('zlib.deflate');
252252
253253$ret = $fun('hello') . $fun('world') . $fun();
254254assert('helloworld' === gzinflate($ret));
@@ -258,7 +258,7 @@ The filter function must not be used anymore after it has been closed.
258258Doing so will result in a ` RuntimeException ` :
259259
260260``` php
261- $fun = Filter \fun('string.rot13');
261+ $fun = Clue\StreamFilter \fun('string.rot13');
262262$fun();
263263
264264$fun('test'); // throws RuntimeException
@@ -277,15 +277,15 @@ The `remove(resource<stream filter> $filter): bool` function can be used to
277277remove a filter previously added via [ ` append() ` ] ( #append ) or [ ` prepend() ` ] ( #prepend ) .
278278
279279``` php
280- $filter = Filter \append($stream, function () {
280+ $filter = Clue\StreamFilter \append($stream, function () {
281281 // …
282282});
283- Filter \remove($filter);
283+ Clue\StreamFilter \remove($filter);
284284```
285285
286286## Install
287287
288- The recommended way to install this library is [ through Composer] ( https://getcomposer.org ) .
288+ The recommended way to install this library is [ through Composer] ( https://getcomposer.org/ ) .
289289[ New to Composer?] ( https://getcomposer.org/doc/00-intro.md )
290290
291291This project follows [ SemVer] ( https://semver.org/ ) .
@@ -300,13 +300,13 @@ See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
300300This project aims to run on any platform and thus does not require any PHP
301301extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
302302HHVM.
303- It's * highly recommended to use PHP 7+ * for this project.
303+ It's * highly recommended to use the latest supported PHP version * for this project.
304304Older PHP versions may suffer from a number of inconsistencies documented above.
305305
306306## Tests
307307
308308To run the test suite, you first need to clone this repo and then install all
309- dependencies [ through Composer] ( https://getcomposer.org ) :
309+ dependencies [ through Composer] ( https://getcomposer.org/ ) :
310310
311311``` bash
312312$ composer install
@@ -315,7 +315,7 @@ $ composer install
315315To run the test suite, go to the project root and run:
316316
317317``` bash
318- $ php vendor/bin/phpunit
318+ $ vendor/bin/phpunit
319319```
320320
321321## License
0 commit comments