elvenspellmaker/pipesys
Composer 安装命令:
composer require elvenspellmaker/pipesys
包简介
A system of "pipes" for PHP.
README 文档
README
PipeSys (said Pipes) is a very basic system of pipes implemented in PHP.
Requirements
- PHP >= 5.6
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 yielding 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
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:
<?php include 'vendor/autoload.php'; use ElvenSpellmaker\PipeSys as PS; use ElvenSpellmaker\PipeSys\Command as Command; $connector = new Command\StandardConnector; $c = new PS\Scheduler($connector); $c->addCommand(new Command\ChattyYes); $c->addCommand(new Command\Head)); $c->run(); Output: Yes I Am Chatty Yes I Am Chatty Yes I
ChattyYes | grep "Chatty" | head
The above chain shows that ChattyYes is connected to stdIn and it outputs to grep which is looking for the phrase "Chatty" and its output is connected to head which will print the first 10 lines it receives.
The PHP code for this is below:
<?php include 'vendor/autoload.php'; use ElvenSpellmaker\PipeSys as PS; use ElvenSpellmaker\PipeSys\Command as Command; $connector = new Command\StandardConnector; $c = new PS\Scheduler($connector); $c->addCommand(new Command\ChattyYes); $c->addCommand(new Command\Grep('Chatty')); $c->addCommand(new Command\Head)); $c->run(); Output: Chatty Chatty Chatty Chatty Chatty Chatty Chatty Chatty Chatty Chatty
elvenspellmaker/pipesys 适用场景与选型建议
elvenspellmaker/pipesys 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 81 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 elvenspellmaker/pipesys 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 elvenspellmaker/pipesys 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 81
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-09