badtomcat / pipeline

pipeline

安装: 34

依赖者: 1

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

公开问题: 0

类型:项目

v0.0.1 2017-12-20 05:24 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:31:25 UTC


README

function dispatchToRouter()
{
    return function ($request) {
        echo '>>>'.$request . PHP_EOL;
    };
}

$request = 10;

$middlewares = [
    function($a,$next){
        var_dump($a);
        return $next($a + 5);
    },
    function($b,$next){
        var_dump($b);
        return $next($b * 2);
    },
    function($c,$next){
        var_dump($c);
        $r = $next($c - 1);
        return $r;
    },
];

> 函数的返回值为第一个PIPE的返回值

(new pipe())->send(1)->through($middlewares)->then(dispatchToRouter());


$middlewares = [
    function($a,$next){
        $next($a + 5);
        var_dump($a);
    },
    function($b,$next){
        $next($b * 2);
        var_dump($b);
    },
    function($c,$next){
        $next($c - 1);
        var_dump($c);
    },
];

(new pipe())->send(1)->through($middlewares)->then(dispatchToRouter());