omarlon/php-router
Composer 安装命令:
composer require omarlon/php-router
包简介
A PHP router with a syntax like a Laravel
关键字:
README 文档
README
Installation
Install using composer or include Router.php. For cleaner urls use the following .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Example
Registering a route that responds to "GET /":
Route::get('/', function()
{
return "Hello World!";
});
Registering a route that is valid for any HTTP verb (GET, POST, PUT, and DELETE):
Route::any('/', function()
{
return "Hello World!";
});
Registering routes for other request methods:
Route::post('user', function()
{
//
});
Route::put('user/(:num)', function($id)
{
//
});
Route::delete('user/(:num)', function($id)
{
//
});
Registering a single URI for multiple HTTP verbs:
Route::register(array('GET', 'POST'), $uri, function()
{
//
});
Registering a route that is only valid for HTTPS requests:
Route::secure('GET', '/', function()
{
//
});
Wildcards
Forcing a URI segment to be any digit:
Route::get('user/(:num)', function($id)
{
//
});
Allowing a URI segment to be any alpha-numeric string:
Route::get('post/(:any)', function($title)
{
//
});
Catching the remaining URI without limitations:
Route::get('files/(:all)', function($path)
{
//
});
Allowing a URI segment to be optional:
Route::get('page/(:any?)', function($page = 'index')
{
//
});
Controller Routing
Controllers provide another way to manage your application logic. It is important to be aware that all routes must be explicitly defined, including routes to controllers. This means that controller methods that have not been exposed through route registration cannot be accessed. It's possible to automatically expose all methods within a controller using controller route registration.
Registering the "home" controller with the Router:
Route::controller('home');
Registering several controllers with the router:
Route::controller(array('dashboard.panel', 'admin'));
This convention is similar to that employed by CodeIgniter and other popular frameworks, where the first segment is the controller name, the second is the method, and the remaining segments are passed to the method as arguments. If no method segment is present, the "index" method will be used.
This routing convention may not be desirable for every situation, so you may also explicitly route URIs to controller actions using a simple, intuitive syntax.
Registering a route that points to a controller action:
Route::get('welcome', 'home@index');
Extras
Get your site base URL:
Router::base();
Get the current URI:
Router::uri();
omarlon/php-router 适用场景与选型建议
omarlon/php-router 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php router」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 omarlon/php-router 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 omarlon/php-router 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 omarlon/php-router 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Router
PMVC App Action Router
Database alias router extension for Nette Framework
Alfabank REST API integration
PHP Router
A PSR7 / PSR-15 compatible HTTP router.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-17