hyperf中间件

>什么是中间件

`中间件主要用于编织从 请求(Request) 到 响应(Response) 的整个流程,通过对多个中间件的组织,使数据的流动按我们预定的方式进行`

生成中间件

```
php ./bin/hyperf.php gen:middleware Middleware1
php ./bin/hyperf.php gen:middleware Middleware2
```

middleware1.php

```
container = $container;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
echo 'middleware1'.PHP_EOL;
return $handler->handle($request);
}
}
```
middleware2.php
```
container = $container;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
echo 'middleware2'.PHP_EOL;
return $handler->handle($request);
}
}
```

配置路由

```
[Middleware1::class,Middleware2::class]]);
```

创建控制器

```

    A+
发布日期:2021年12月30日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: