PHPackages                             elvenspellmaker/pipesys - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. elvenspellmaker/pipesys

ActiveLibrary

elvenspellmaker/pipesys
=======================

A system of "pipes" for PHP.

2.0.3(6y ago)0811MITPHPPHP &gt;=5.6.0CI failing

Since May 22Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ElvenSpellmaker/PipeSys)[ Packagist](https://packagist.org/packages/elvenspellmaker/pipesys)[ RSS](/packages/elvenspellmaker-pipesys/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (5)Dependencies (3)Versions (7)Used By (0)

PipeSys [![Build Status](https://camo.githubusercontent.com/ff74cd03f82f1b0c98801d1fe1979d45e98b582ff863680456b6be6b1b43ae59/68747470733a2f2f7472617669732d63692e636f6d2f456c76656e5370656c6c6d616b65722f506970655379732e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/ElvenSpellmaker/PipeSys)
============================================================================================================================================================================================================================================================================================================

[](#pipesys-)

PipeSys (*said Pipes*) is a very basic system of pipes implemented in PHP.

Requirements
------------

[](#requirements)

- PHP &gt;= 5.6

How it works
------------

[](#how-it-works)

The way PipeSys works is by having a chain of commands which are joined together by the Scheduler to give the effect of pipes by chaining the output of one to the input of another. A Scheduler can have many commands added to it and all must be an instance of `AbstractCommand`.

Commands are special classes which have a `getCommand` method which should return a Generator, i.e. it should have `yield` statements in it. When a command wants to read it should use a coroutine call like:

```
$input = (yield new ReadIntent);
```

By `yield`ing a `ReadIntent` object the command knows it wants to read in order to continue. When data is available for the command it it sent using the `send()` generator method. `$input` will pick up this sent value and the generator will resume.

When a command wants to write it should yield an `OutputIntent` signalling that it has the intention to output something:

```
yield new OutputIntent('Hello World!');
```

The output data can be anything you like and may even be sent to another channel, such as `StdErr`:

```
yield new OutputIntent('Hello World!', IOConstants::IO_STDERR);
```

Commands at the start or end have access to the `stdin` or `stdout` respectively of the Scheduler which may correspond to the `stdin` and `stdout` of the system. (Provided by the `StdIn` and `StdOut` classes.)

The commands are connected by a `ConnectorInterface` implementing class, which allows you to customise and fine-tune the connection behaviour. A default conntector called `StandardConnector` is provided which will connect the first command's input to the StdIn of the system, the last command's output to the StdOut of the system, all other commands link their outputs and inputs in a chain (like UNIX pipes) and all commands get connected to the StdErr channel too.

The Scheduler uses coöperative scheduling, because PHP is single process and single threaded there is no way to implement preëmptive scheduling without an extension.

When a stdin method is exhausted it should return an `EOF` object.The `EOF`signals that the end of the stream (EOF = End Of File) has been reached. Commands that read will most likely want to return once receiving this as they usually can't continue any further without anything to read.

Terminating commands should `yield null` to tell the system they can no longer function any more.

Example Code
------------

[](#example-code)

Examples of simple command chains are shown below.

`ChattyYes` is similar to the Unix `Yes` command except instead of `y` being output it outputs:

```
Yes
I
Am
Chatty

```

over and over.

```
ChattyYes | head
```

The above chain shows that ChattyYes is connected to stdIn and its output is connected to head which will print the first 10 lines it receives.

The PHP code for this is below:

```
