b2pweb/bdf-pipeline
最新稳定版本:v1.1.1
Composer 安装命令:
composer require b2pweb/bdf-pipeline
包简介
Bdf Pipeline component
README 文档
README
A PHP Pipeline pattern.
Install via composer
$ composer require b2pweb/bdf-pipeline
Usage Instructions
A basic and classic use of pipeline with a pipe processor.
use Bdf\Pipeline\Pipeline; use Bdf\Pipeline\CallableFactory\LinkedCallableFactory; $pipeline = new Pipeline(new LinkedCallableFactory()); $pipeline->pipe(function($value) { return $value + 2; }); // Returns 12 $pipeline->send(10);
The pipeline lib comes with an advanced processor (used by default).
use Bdf\Pipeline\Pipeline; use Bdf\Pipeline\CallableFactory\StackCallableFactory; $pipeline = new Pipeline(new StackCallableFactory()); $pipeline->pipe(function($next, $foo, $bar) { // Do something ... $result = $next($foo, $bar); // Do something else ... return $result; }); $pipeline->outlet(function($foo, $bar) { return "${foo}.${bar}"; }); // Manage multiple parameters echo $pipeline->send('foo', 'bar'); // Print foo.bar
Ok, So ?
You can use this package as a classic pipe, but it was designed to be easily extended:
$pipeline->pipe(new LogCommand()); $pipeline->outlet(new CreateUserHandler()); ... $pipeline->prepend(new TransactionnalCommand()); $pipeline->send(new CreateUserCommand());
class TransactionnalCommand { public function __invoke($next, $command) { try { $result = $next($command); // Commit and return the result ... return $result; } catch (\Throwable $exception) { // Rollback and propagate exception throw $exception; } } }
The pipeline is reusable:
$pipeline = new Pipeline(); $pipeline->pipe(new Double()); $new = clone $pipeline; $new->pipe(new Double()); echo $pipeline->send(2); // 4 echo $new->send(2); // 8
License
Distributed under the terms of the MIT license.
统计信息
- 总下载量: 3.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-28