1
1
# Middleware
2
2
3
- the psr-15 HTTP Middleware implement.
3
+ The psr-15 HTTP Middleware implement.
4
4
5
- ref https://github.com/php-fig/fig-standards/blob/master/proposed/http- handlers/middleware .md
5
+ ref [ PSR 15 ] ( https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-15-request- handlers.md )
6
6
7
7
8
8
## 项目地址
@@ -129,24 +129,24 @@ n after >>>
129
129
response content: node 4 + node 3 + node 2 + node 1
130
130
```
131
131
132
- ### 一个基于中间件的应用
132
+ ## 一个基于中间件的应用示例
133
133
134
- - 引入相关类
134
+ ### 引入相关类
135
135
136
136
路由器,psr 7的http message 库
137
137
138
138
``` php
139
139
use Inhere\Http\HttpFactory;
140
- use Inhere\Library\Helpers\ Http;
140
+ use Inhere\Http\HttpUtil ;
141
141
use Inhere\Middleware\MiddlewareStackAwareTrait;
142
- use Inhere\Middleware\RequestHandlerInterface ;
142
+ use Inhere\Route\Base\RouterInterface ;
143
143
use Inhere\Route\ORouter;
144
- use Inhere\Route\RouterInterface;
145
144
use Psr\Http\Message\ResponseInterface;
146
145
use Psr\Http\Message\ServerRequestInterface;
146
+ use Psr\Http\Server\RequestHandlerInterface;
147
147
```
148
148
149
- - 创建一个应用类
149
+ ### 创建一个应用类
150
150
151
151
``` php
152
152
@@ -206,7 +206,7 @@ $app = new class implements RequestHandlerInterface {
206
206
};
207
207
```
208
208
209
- - 创建路由器并注册路由
209
+ ### 创建路由器并注册路由
210
210
211
211
``` php
212
212
$router = new ORouter();
@@ -224,7 +224,7 @@ $router->get('/hello/{name}', function ($args) {
224
224
225
225
```
226
226
227
- - 添加中间件
227
+ ### 添加中间件
228
228
229
229
``` php
230
230
/**
@@ -247,7 +247,7 @@ $app->use(function (ServerRequestInterface $request, RequestHandlerInterface $ha
247
247
});
248
248
```
249
249
250
- - 准备运行
250
+ ### 准备运行
251
251
252
252
``` php
253
253
/**
@@ -259,7 +259,7 @@ $app->setRouter($router);
259
259
$app->run($req);
260
260
```
261
261
262
- - 运行server
262
+ ### 运行dev server
263
263
264
264
``` bash
265
265
$ php -S 127.0.0.1:8009 examples/app.php
0 commit comments