Skip to content

Commit a9f0300

Browse files
committed
update readme
1 parent bceca8c commit a9f0300

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818
> 不同的版本有稍微的区别以适应不同的场景
1919
20-
- `ORouter` 通用版本,也是后几个版本的基础类。
20+
- `ORouter` 通用版本,也是后几个版本的基础类,适用于所有的情况
2121
- `SRouter` 静态类版本。`ORouter` 的简单包装,通过静态方法使用(方便小应用快速使用)
22-
- `CachedRouter` 继承自`ORouter`,支持路由缓存的版本. 适合fpm使用(有缓存将会省去每次的路由收集和解析消耗)
23-
- `PreMatchRouter` 继承自`ORouter`,预匹配路由器。当应用的静态路由较多时,将拥有更快的匹配速度
24-
- fpm 应用中,实际上我们在收集路由之前,已经知道了路由path和请求动作METHOD
25-
- `ServerRouter` 继承自`ORouter`,服务器路由。内置支持动态路由临时缓存. 适合swoole等常驻内存应用使用
26-
- 最近请求过的动态路由将会缓存为一个静态路由信息,下次相同路由将会直接匹配命中
22+
- `CachedRouter` 继承自`ORouter`,支持路由缓存的版本,可以 **缓存路由信息到文件**
23+
- 适合php-fpm 环境使用(有缓存将会省去每次的路由收集和解析消耗)
24+
- `PreMatchRouter` 继承自`ORouter`,预匹配路由器。**当应用的静态路由较多时,将拥有更快的匹配速度**
25+
- 适合php-fpm 环境,php-fpm 情形下,实际上我们在收集路由之前,已经知道了路由path和请求动作METHOD
26+
- `ServerRouter` 继承自`ORouter`,服务器路由。内置支持**动态路由临时缓存**. 适合 `swoole`**常驻内存应用**使用
27+
- 最近请求过的动态路由将会缓存为一个静态路由信息,下次相同路由将会直接匹配命中
2728

2829
**内置调度器:**
2930

@@ -180,25 +181,38 @@ $router->any('/home', function() {
180181
$router->any('/404', function() {
181182
echo "Sorry,This page not found.";
182183
});
184+
```
185+
186+
### 使用路由组
183187

188+
```php
184189
// 路由组
185-
$router->group('/user', function () {
190+
$router->group('/user', function ($router) {
186191
$router->get('/', function () {
187192
echo 'hello. you access: /user/';
188193
});
189194
$router->get('/index', function () {
190195
echo 'hello. you access: /user/index';
191196
});
192197
});
198+
```
199+
200+
### 使用控制器
193201

202+
```php
194203
// 使用 控制器
195204
$router->get('/', App\Controllers\HomeController::class);
196205
$router->get('/index', 'App\Controllers\HomeController@index');
197206

198207
// 使用 rest() 可以快速将一个控制器类注册成一组 RESTful 路由
199208
$router->rest('/users', App\Controllers\UserController::class);
209+
```
210+
211+
### 备用路由处理
200212

201-
// 可以注册一个备用路由处理。 当没匹配到时,就会使用它
213+
可以注册一个备用路由处理。当没匹配到时,就会使用它
214+
215+
```php
202216
$router->any('*', 'fallback_handler');
203217
```
204218

src/Base/AbstractRouter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public function parseParamRoute(string $route, array $params, array $conf): arra
508508

509509
// first node is a normal string
510510
// e.g '/user/{id}' first: 'user', '/a/{post}' first: 'a'
511-
if (\preg_match('#^/([\w-]+)/[\w-]*/?#', $backup, $m)) {
511+
if (\preg_match('#^/([\w-]+)/#', $backup, $m)) {
512512
$conf['start'] = $start;
513513

514514
return [$m[1], $conf];

0 commit comments

Comments
 (0)