定制 dlpwd/router 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dlpwd/router

Composer 安装命令:

composer require dlpwd/router

包简介

Lightweight router library with named url parameters

关键字:

README 文档

README

Lightweight router library with named url parameters

Basic Usage

$router = new \dlpwd\router\Router();

$router->get('/', '\\dlpwd\\sample\\controller\\dashboard::renderDashboard');
$router->get('/login', '\\dlpwd\\sample\\controller\\login::showLoginForm');
$router->post('/login', '\\dlpwd\sample\\controller\\login::processLogin');
$router->get('/page/{friendlyUrl}', '\\dlpwd\\sample\\controller\\page::showPage');

$router->resolve();

Configuring Routes

The router supports three request methods, GET, POST and DELETE. There are corresponding methods in the router class to add routes for each request method

Router::get($_url, $_handler);
Router::post($_url, $_handler);
Router::delete($_url, $_handler);
Router::addRoute($_method, $_url, $_handler);

$_method

The request method can be specified when using the addRoute method on the router to create a new route. This method is useful when adding routes in bulk, for example after loading from a database or file, rather than using hard-coded routes.

$_url

The URL for the route should be specified with a leading forward-slash. Trailing forward-slashes are optional. The router will match requests with and without a trailing forward-slash to the same route. Parameters are specified within curly-braces. The name of the parameters must match the name of the parameters on the handler function, otherwise they will not be passed through

$_handler

The handler argument specifies the function to call if the route matches. The function can be specified in as any valid PHP callable

Resolving Routes

To have the router examine a URL and call the relevant controller, execute the resolve method. The resolve method will return any value returned by the controller function

Router::resolve($_url, $_method);

$_url

Omitting or passing null to the $_url parameter will cause the router to use the value of $_SERVER['REQUEST_URI']. Pass a url to this argument to manually run the router for a different URL than the one being requested

$_method

Omitting or passing null to the $_method parameter will cause the router to use the value of $_SERVER['REQUEST_METHOD']. Pass a method to this argument to override that value. Most useful when manually running the router with a different URL as above

dlpwd/router 适用场景与选型建议

dlpwd/router 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.54k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 08 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「router」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dlpwd/router 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dlpwd/router 我们能提供哪些服务?
定制开发 / 二次开发

基于 dlpwd/router 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.54k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-27