fernandovaller/vrouter
Composer 安装命令:
composer require fernandovaller/vrouter
包简介
Sistema de rotas para php 5.6
README 文档
README
Esse projeto é baseado em um fork do projeto [https://github.com/robsonvleite/router] mas modificado para funcionar na versão do PHP 5.6
Installation
Router is available via Composer:
composer require fernandovaller/vrouter
.htaccess in apache
RewriteEngine On
#Options All -Indexes
## ROUTER WWW Redirect.
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
## ROUTER HTTPS Redirect
#RewriteCond %{HTTP:X-Forwarded-Proto} !https
#RewriteCond %{HTTPS} off
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ROUTER URL Rewrite
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=/$1 [L,QSA]
Routes
<?php require __DIR__ . "/../vendor/autoload.php"; use FVCode\VRouter\Router; $router = new Router("https://www.youdomain.com"); /** * routes * The controller must be in the namespace Test\Controller * this produces routes for route, route/$id, route/{$id}/profile, etc. */ $router->SetNamespace("Test"); $router->get("/route", "Controller:method"); $router->post("/route/{id}", "Controller:method"); $router->put("/route/{id}/profile", "Controller:method"); $router->patch("/route/{id}/profile/{photo}", "Controller:method"); $router->delete("/route/{id}", "Controller:method"); // CRUD - [index, show, modal, create, store, edit, update, destroy] $router->resource("/usuarios", "UsuarioController", 'usuarios'); $router->any(['GET','POST']", /usuarios", "UsuarioController", 'usuarios'); /** * group by routes and namespace * this produces routes for /admin/route and /admin/route/$id * The controller must be in the namespace Dash\Controller */ $router->group("admin")->namespace("Dash"); $router->get("/route", "Controller:method"); $router->post("/route/{id}", "Controller:method"); /** * Group Error * This monitors all Router errors. Are they: 400 Bad Request, 404 Not Found, 405 Method Not Allowed and 501 Not Implemented */ $router->group("error")->namespace("Test"); $router->get("/{errcode}", "Coffee:notFound"); /** * This method executes the routes */ $router->dispatch(); /* * Redirect all errors */ if ($router->error()) { $router->redirect("/error/{$router->error()}"); }
Named
<?php require __DIR__ . "/../vendor/autoload.php"; use FVCode\VRouter\Router; $router = new Router("https://www.youdomain.com"); /** * routes * The controller must be in the namespace Test\Controller */ $router->namespace("Test")->group("name"); $router->get("/", "Name:home", "name.home"); $router->get("/hello", "Name:hello", "name.hello"); $router->get("/redirect", "Name:redirect", "name.redirect"); /** * This method executes the routes */ $router->dispatch(); /* * Redirect all errors */ if ($router->error()) { $router->redirect("name.hello"); }
Named Controller Exemple
class Name { public function __construct($router) { $this->router = $router; } public function home() { echo "<h1>Home</h1>"; echo "<p>", $this->router->route("name.home"), "</p>"; echo "<p>", $this->router->route("name.hello"), "</p>"; echo "<p>", $this->router->route("name.redirect"), "</p>"; } public function redirect() { $this->router->redirect("name.hello"); } }
Named Params
//route $router->get("/params/{category}/page/{page}", "Name:params", "name.params"); //$this->route = return URL //$this->redirect = redirect URL $this->router->route("name.params", [ "category" => 22, "page" => 2 ]); //result https://www.{}/name/params/22/page/2 $this->router->route("name.params", [ "category" => 22, "page" => 2, "argument1" => "most filter", "argument2" => "most search" ]); //result https://www.{}/name/params/22/page/2?argument1=most+filter&argument2=most+search
fernandovaller/vrouter 适用场景与选型建议
fernandovaller/vrouter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 177 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 03 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「route」 「router」 「routes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fernandovaller/vrouter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fernandovaller/vrouter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fernandovaller/vrouter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
Block routes by IP
Provides caching methods which can be easily used for caching routes.
Provide a way to secure accesses to all routes of an symfony application.
Write down your routing mapping at one place
A Laravel-like router for the WordPress Rewrite API
统计信息
- 总下载量: 177
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-13