当前位置:网站首页>Thinkphp6 pipeline mode pipeline use
Thinkphp6 pipeline mode pipeline use
2022-07-29 05:51:00 【Liaoshengping】
Reading guide
Look at the use on the network Tp There are very few examples of pipeline mode , It is used to analyze the application scenarios of Middleware in the framework , In fact, the pipeline mode is also very easy to use in business development .
Most of them are found on the Internet Laravel Example , however Laravel In the example of Tp It's impossible , After groping , We finally got it Tp Use

No one discussed the pipeline mode on the official website , And in the Learnku A lot of people discussed , This explains The framework is comparable .
So I searched the source code , from Think Unit test of middleware , Loading process to middleware , Finally found the format here , It looks like this :
/** * Parsing middleware * @access protected * @param mixed $middleware * @param string $type Middleware type * @return array */
protected function buildMiddleware($middleware, string $type): array
{
if (is_array($middleware)) {
[$middleware, $params] = $middleware;
}
if ($middleware instanceof Closure) {
return [$middleware, $params ?? []];
}
if (!is_string($middleware)) {
throw new InvalidArgumentException('The middleware is invalid');
}
// Middleware alias check
$alias = $this->app->config->get('middleware.alias', []);
if (isset($alias[$middleware])) {
$middleware = $alias[$middleware];
}
if (is_array($middleware)) {
$this->import($middleware, $type);
return [];
}
return [[$middleware, 'handle'], $params ?? []];
}
It needs to pass handle Method , commonly Laravel And pipelines in other mainstream frameworks are default handle Method , It can't be said that such a design is bad , But at least there must be a default method , Who knows how to write this without documentation .
Get ready
class Test
{
public static function handle($request,$next){
echo ' I'm middleware 1';
$next($request);
}
}
class Test2
{
public static function handle($request,$next){
$next($request);
echo ' I'm middleware 222';
}
}
class Request
{
}
Use
$request = new Request();
$pips[] = [\app\common\service\order\pipeline\Test::class,'handle'];
$pips[] = [\app\common\service\order\pipeline\Test2::class,'handle'];
(new Pipeline())
->send($request)
->through($pips)
->then(function ($e) {
});
Case study
边栏推荐
- 与张小姐的春夏秋冬(4)
- 闪贷Dapp的调研及实现
- 与张小姐的春夏秋冬(3)
- 识变!应变!求变!
- Training log 7 of the project "construction of Shandong University mobile Internet development technology teaching website"
- Fantom (FTM) prices will soar by 20% in the next few days
- Reporting Service 2016 自定义身份验证
- H5 semantic label
- “山东大学移动互联网开发技术教学网站建设”项目实训日志一
- 微信内置浏览器禁止缓存的问题
猜你喜欢

Breaking through the hardware bottleneck (I): the development of Intel Architecture and bottleneck mining

JDBC连接数据库详细步骤

php写一个购买全网最低价的纸尿裤

How to survive in the bear market of encryption market?

深度学习的趣味app简单优化(适合新手)

Training log II of the project "construction of Shandong University mobile Internet development technology teaching website"

“山东大学移动互联网开发技术教学网站建设”项目实训日志五

机器学习让文字识别更简单:Kotlin+MVVM+华为ML Kit

“山东大学移动互联网开发技术教学网站建设”项目实训日志三

The LAAS protocol of defi 2.0 is the key to revitalizing the development of defi track
随机推荐
闪贷Dapp的调研及实现
IDEA使用JDBC连接MySQL数据库个人详细教程
July 28 ens/usd Value Forecast: ENS attracts huge profits
centos7 静默安装oracle
Bare metal cloud FASS high performance elastic block storage solution
JDBC连接数据库详细步骤
Dao race track is booming. What are the advantages of m-dao?
The bear market is slow, and bit.store provides stable stacking products to help you get through the bull and bear market
北京宝德&TaoCloud共建信创之路
Flink connector Oracle CDC 实时同步数据到MySQL(Oracle12c)
Differences between href and SRC
完全去中心化的编程模式,不需要服务器,也不需要ip,就像一张漫无目的的网络、四处延伸
Super simple integration HMS ml kit face detection to achieve cute stickers
Reporting Service 2016 自定义身份验证
Training log 7 of the project "construction of Shandong University mobile Internet development technology teaching website"
MOVE PROTOCOL全球健康宣言,将健康运动进行到底
Research and implementation of flash loan DAPP
量化开发必掌握的30个知识点【什么是Level-2数据】
iSCSI vs iSER vs NVMe-TCP vs NVMe-RDMA
与张小姐的春夏秋冬(5)