charm/fsrouter-middleware

一个通过文件系统路径定义路由的路由器。

1.0.3 2022-03-04 12:27 UTC

This package is auto-updated.

Last update: 2024-09-04 17:54:33 UTC


README

一个将路径转换为文件系统中的文件名的路由器实现。也可以用作PSR-15路由中间件。

字符串hello/world按照以下近似顺序路由到以下路径之一。目标文件名index.phpdefault.php以及扩展名.php均可配置。

  • routes/hello/world/index.php
  • routes/hello/world/default.php
  • routes/hello/world.php
  • routes/_/world/index.php
  • routes/_/world/default.php
  • routes/_/world.php
  • routes/hello/_/index.php
  • routes/hello/_/default.php
  • routes/_/_/index.php
  • routes/_/_/default.php
  • routes/_/default.php
  • routes/default.php

注意!此顺序是近似的。从根目录开始解析,优先进入目录。当路由失败时,它将退出目录并查找

创建路由器实例

new FsRouterMiddleware([
    'routes_path' => dirname(__DIR__).'/routes'
])