jcain / router-ss
适用于 PHP 7.4+ 的 HTTP 路由微型库。
v0.9
2020-08-14 14:29 UTC
Requires
- php: ^7.2
- jcain/asserts-lr: ^0.0.0
README
Router SS 是适用于 PHP 7.2+ 的 HTTP 路由微型库。
安装
Router SS 需要 PHP 7.2 或更高版本。
composer require jcain/router-ss
使用方法
创建一个包含以下内容的 router.php 文件
<?php
require_once __DIR__ . '/vendor/autoload.php';
use \JCain\Router\SS\Requests\BasicRequest;
use \JCain\Router\SS\Requests\StringEvaluator;
use \JCain\Router\SS\Routers\BasicRouter;
$request = new BasicRequest([
'variables' => BasicRequest::parseRequestInfo(),
]);
$router = new BasicRouter([ 'outputExceptions' => true ]);
$router->route($request, function ($r) {
$path = new StringEvaluator($r, 'path');
$path->equals('', function ($r) {
echo '<a href="hello-world">Click here to greet the world<a><br />';
echo 'or<br />';
echo '<a href="hello-universe">Click here to greet the universe<a><br />';
});
$path->matches('^hello-(?<name>[^/]+)$', function ($r) {
$name = ucwords(urldecode($r->getVariable('name')));
echo "Hello, $name!";
});
});
运行内置的 PHP 服务器
php -S localhost:8080 router.php
然后访问 https://:8080/。
组件稳定性状态
| 组件 | 稳定性 | 自 |
|---|---|---|
| fallthrough | alpha | 0.9 |
| HandledException | alpha | 0.0 |
| 处理器 | alpha | 0.0 |
| HttpStatusException | alpha | 0.0 |
| 请求 | alpha | 0.0 |
| RequestProvider | alpha | 0.9 |
| Router | alpha | 0.9 |
| 处理器/PhpFileHandler | alpha | 0.7 |
| 处理器/RawFileHandler | alpha | 0.7 |
| 匹配器/BasicMatchers | alpha | 0.9 |
| 匹配器/MethodMatchers | alpha | 0.9 |
| 匹配器/MethodMatchersTrait | alpha | 0.7 |
| 匹配器/PathMatchers | alpha | 0.9 |
| 匹配器/PathMatchersTrait | alpha | 0.7 |
| 请求/BasicRequest | alpha | 0.9 |
| 请求/RequestBase | alpha | 0.9 |
| 请求/RequestWrapper | alpha | 0.9 |
| 请求/TracingRequest | alpha | 0.9 |
| 路由器/BasicRouter | alpha | 0.9 |
稳定性 列表示组件的稳定性状态,而 自 列表示组件首次达到该稳定性时的包的主要版本。
每个组件及其成员都有一个表示其在生产中依赖的接口和实现的稳定性的 稳定性状态。稳定性可能是以下之一
- alpha:接口和实现是不稳定的,可能会发生重大变化。
- beta:接口是稳定的,但其实现尚未得到充分测试。
- omega:接口和实现都是稳定的,被认为适用于生产使用。
组件的稳定性状态与其成员的最高稳定性状态相同。一旦成员的稳定性提高,它将不会降低。
许可协议
Router SS 采用 MIT 许可协议。有关更多信息,请参阅 LICENSE 文件。