An elegant PHP middleware pipeline. - 一个优雅的 PHP 中间件管道。
- PHP >= 7.2
$ composer require guanguans/pipeline --prefer-dist -vvv
<?php
require __DIR__.'/vendor/autoload.php';
use Guanguans\Pipeline\Pipeline;
(new Pipeline())
->send('passable')
->through(
function ($passable, Closure $next){
echo '1. Before apply first middleware.'.PHP_EOL;
$next($passable);
echo '7. After apply first middleware.'.PHP_EOL;
},
function ($passable, Closure $next){
echo '2. Before apply second middleware.'.PHP_EOL;
$next($passable);
echo '6. After apply second middleware.'.PHP_EOL;
},
function ($passable, Closure $next){
echo '3. Before apply third middleware.'.PHP_EOL;
$next($passable);
echo '5. After apply third middleware.'.PHP_EOL;
}
)
// ->via('differentMethod')
// ->thenReturn()
->then(function ($passable){
echo '4. Middleware is finished.'.PHP_EOL;
return $passable;
});
1. Before apply first middleware.
2. Before apply second middleware.
3. Before apply third middleware.
4. Middleware is finished.
5. After apply third middleware.
6. After apply second middleware.
7. After apply first middleware.
$ composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.