legionth/indentation-react
This project should show how awesome streams are and why they should be used. This project use a combination of writable and readable streams. Checkout the Usage for more information., (*1)
Table of Contents
* Usage
* Indenter
* Install
* License, (*2)
Usage
Indenter
The center of this project is the Indenter class. This class (obviously) indents the incomig stream into an outgoing stream. The Indenter is an EventEmitter and a ReadableStreamInterface. Because this class is a ReadableStreamInterface the indented data will be exposed on the same interface., (*3)
To use this data you have to pipe it into another stream, checkout the examples folder., (*4)
So what is the reason for this project? This project just shows how awesome the ReactPHP streams are. Streams can come in different sizes: bigger parts, smaller parts, etc. depending on your data source(Downloads, Files, Strings ...).
In this project you can be sure a chunk is complete when the new line delimiter comes in, so the next line will be indented. So you can be sure the stream is always correctly indented., (*5)
You can find under examples how you can use this project.
If you need a file to be indented you can pipe the file into the example., (*6)
$ cat words.txt | php examples/indentInput.php
This command can be started on its own., (*7)
$ php examples/indentInput.php
This example makes clear why this project should be used. You can indent a whole file with one little example. If you want, you can pipe a command output into this example to see how it works. Just try it., (*8)
You can use other indentation methods as the standard 4 spaces e.g. (Tabs, more or fewer spaces) by using it like this, (*9)
$ cat words.txt | php examples/indentInput.php --tab
or just add two spaces instead of four:, (*10)
$ cat words.txt | php examples/indentInput.php --spaces 2
Use it in your production code like this;, (*11)
$indenter = new Indenter($inputStream);
// or
$indenter = new Indenter($inputStream, $beginningString);
The $beginningString can be any kind of string. Whatever you prefer ;), (*12)
Install
The recommended way to install this library is through Composer.
New to Composer?, (*13)
This will install the latest supported version:, (*14)
$ composer require legionth/indentation-react:^0.1
See also the CHANGELOG for details about version upgrades., (*15)
License
MIT, (*16)