hybridlogic/router
Composer 安装命令:
composer require hybridlogic/router
包简介
A drop dead simple URI routing library for PHP, with support for optional parameters and regular expressions.
README 文档
README
A drop dead simple URI routing library for PHP, with support for optional parameters and regular expressions.
0.0 Table of Contents
- Introduction
- Examples
- Format
- Running Tests
- Troubleshooting
- Changelog
1.0 Introduction
Router is a very simple URI request routing library, designed for providing a simple front controller for applications. A request is run against a dictionary of routes, and the first one to match is executed.
It supports expansions for common expressions (numeric, slugs etc), along with full regexes and optional parameter support.
Can be used in front of a full MVC stack, or with simple in-place closures.
2.0 Examples
$router = new \HybridLogic\Router; $router->get('about', function(){ echo 'About Us'; }); $router->run();
3.0 Format
Each route you wish to match should have a rule. The rule shouldn't include a beginning or ending slash, except for the homepage, which is just /.
When defining a route, you can specify which HTTP methods it should respond to (GET, POST etc). For example, to only allow GET requests, use ->get(...). A utility method for quickly adding GET and POST is provided via ->any(...).
A route pattern matches a request exactly, that means sub- directories are not included, for example "about" would match /about, but not /about-us or /about/john-smith.
There are three default regex expressions provided:
- :num Matches any numeric value ([0-9]+)
- :any Matches alphanumeric values, including - and _ ([a-z0-9-_]+)
- :all Matches anything, including slashes, will override anything after it
You can also provide your own regex, e.g.
/about/:[a-z][a-z0-9]+
To make a section optional, simply put a question mark (?) at the end, e.g.
/about/:any?
Example patterns:
| Pattern | Matches | Description |
|---|---|---|
| / | / | Homepage |
| about | /about | Matches optional trailing slash |
| about/:any? | /about/john | Match optional directories |
| archive/:num/:num? | /archive/2012/06 | Match archive pattern |
| :all | /matches/anything | Catch-all handler (404s) |
4.0 Running Tests
phpunit tests
5.0 Troubleshooting
Nothing here yet.
6.0 Changelog
- [2012-12-17] Initial Version
- [2012-12-18] Removed 404 handler
- [2012-12-19] Add any() and all() methods.
hybridlogic/router 适用场景与选型建议
hybridlogic/router 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 62 次下载、GitHub Stars 达 12, 最近一次更新时间为 2013 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「router」 「uri」 「request」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hybridlogic/router 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hybridlogic/router 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hybridlogic/router 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Safely namespaced guzzle psr7 for WP2Static
uri signer with expiration option
HTTP request logger middleware for Laravel
Zend Framework 1 Uri package
Adds request-parameter validation to the SLIM 3.x PHP framework
Router
统计信息
- 总下载量: 62
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-12