alexlawford / quickroute
dev-master
2019-03-14 02:04 UTC
Requires
- php: ^7.1
Requires (Dev)
- nette/tester: ^2.2
This package is auto-updated.
Last update: 2024-09-14 19:58:54 UTC
README
简介
Quick route 提供了一个简单的替代方案,用于更高级的路由器,适用于小型项目和原型设计。它完全是函数式的,没有依赖,因此很容易融入任何项目。
路由模式看起来像这样
'users/alpha:name/number:age'
安装
通过 composer
composer require alexlawford/quickroute
示例用法
<?php
require '../vendor/autoload.php';
// Get method and URI from wherever, e.g
// $method = $_SERVER['REQUEST_METHOD'];
// $uri = $_SERVER['REQUEST_URI'];
// the below is for easy testing:
$method = 'GET';
$uri = 'hello/alex/';
$route = (new AlexLawford\QuickRoute)(
$method,
$uri,
[
['GET', 'hello/string:name', function($args) {
echo "<p>Hello $args['name']</p>"
}],
]
);
if($route !== null) {
($route->callback)($route->args);
} else {
// 404
}