solis/highway

HighWay 是一个基于模式构建的简单路由引擎

v0.2.0 2017-08-14 19:40 UTC

This package is auto-updated.

Last update: 2024-09-22 04:12:47 UTC


README

HighWay

HighWay 是一个为从 Slim Framework 3 抽象路由管理过程而开发的机制

如何安装?

该包被设计为通过 composer 安装

composer require solis/highway

如何使用?

首先需要定义一个模式,表示为应用创建的路线

[
    {
       "request": {
         "uri": "/sample/get/",
         "method": "GET",
         "controller": {
           "class": "Sample\\Classes\\Sample",
           "method": "find"
         }
       },
       "middleware": {
          "auth"
        },
       "response": {
         "sType": "withJson"
       }
    }
]

创建 SlimHighWay 类的实例,并使用静态方法 make 将新路线绑定到相应的实例

use HighWay\Wrappers\SlimApp\SlimHighWay;

$routes = json_decode(
    file_get_contents('path/to/Route.json'),
    true
);

$app = SlimHighWay::make(
    $routes
);

$app->run();

SlimHighWay 将负责根据模式中现有的规范创建用于 Slim Framework 3 的路由实例。