guanguans / pipeline
一个优雅的 PHP 中间件管道。 - 一个优雅的 PHP 中间件管道。
v1.0.2
2021-10-16 12:08 UTC
Requires
- php: >=7.2
- psr/container: ^1.1 || ^2.0
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.7
- friendsofphp/php-cs-fixer: ^2.16
- mockery/mockery: ^1.2
- overtrue/phplint: ^2.3 || ^3.0
- phpbench/phpbench: ^1.0
- phpunit/phpunit: ^8.0||^9.0
- vimeo/psalm: ^4.0
README
一个优雅的 PHP 中间件管道。 - 一个优雅的 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
变更日志
请参阅 CHANGELOG 以获取最近更改的详细信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
鸣谢
许可协议
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。