gnumast/pipeline
Composer 安装命令:
composer require gnumast/pipeline
包简介
Simple library to send data through a chain of tasks
README 文档
README
Pipeline allows to easily chain operations / tasks on the fly or create a reusable chain of commands. Complete documentation is available.
Installation
composer require gnumast/pipeline
Basic usage
Here's a trivial example.
class MakeAllCaps implements TaskInterface { public function run($data) { return mb_strtoupper($data); } } class RemoveAllSpaces implements TaskInterface { public function run($data) { return str_replace(' ', '', $data); } } $pipeline = new Pipeline( new MakeAllCaps(), new RemoveAllSpaces() ); $pipeline->execute("Hello, my name is Steve"); // HELLO,MYNAMEISSTEVE
For simple chains where defining a brand new class isn't really worth it, or if you quickly want to chain things
together, the CallablePipe class wraps anonymous functions to be passed as pipes.
$pipeline = new Pipeline( new CallablePipe(function($data) { return $data * 10; }), new CallablePipe(function($data) { return $data + 50; }) ); $result = $pipeline->execute(10); // 150
You don't have to pass all of your tasks at initialisation time. Pipeline provides an add method to add steps
to an existing object:
$pipeline = new Pipeline(new MakeAllCaps()); $pipeline->add(new RemoveAllSpaces()); $pipeline->execute("Hello, world!"); // HELLO,WORLD!
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2015-11-03