Deliverance is a middleware library intended to be used by other framework systems that need to manage multiplex IO operations.
Get news and updates on the DecodeLabs blog.
Install via Composer:
composer require decodelabs/deliverance
Channels represent simple in / out handlers and can be written to and read from:
use DecodeLabs\Deliverance;
$stream = Deliverance::openStream('path/to/file');
$stream->writeLine('Hello world');
$stream = Deliverance::openCliOutputStream(); // Same as new Deliverance\Channel\Stream(STDOUT);
$buffer = Deliverance::newBuffer();
$buffer->write('Some text to buffer');
echo $buffer->read(6); // "Some t"
Channels can be grouped together and managed by an IO Broker
-
use DecodeLabs\Deliverance;
// Create a CLI IO handler
$broker = Deliverance::newBroker()
->addInputProvider(Deliverance::openStream(STDIN))
->addOutputReceiver(Deliverance::openStream(STDOUT))
->addErrorReceiver(Deliverance::openStream(STDERR));
// Shortcut to the above:
$broker = Deliverance::newCliBroker();
// Read line from CLI
$broker->setReadBlocking(true);
$text = $broker->readLine();
// Write it back to output
$broker->writeLine('INPUT: '.$text);
Once grouped, the Channels in an IO broker can be used as the interface between many different information sources; see Systemic Unix process launcher for an example of an IO Broker managing input and output with proc_open()
.
Deliverance is licensed under the MIT License. See LICENSE for the full license text.