定制 alejoluc/via 二次开发

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

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

alejoluc/via

Composer 安装命令:

composer require alejoluc/via

包简介

Simple PHP Router, with prefix groups and filtering

README 文档

README

Simple PHP router with prefix grouping and filters

Work in Progress

This README file is a work in progress and is in the process of being written. In the meantime, please refer to the examples folder to get started.

Usage

Please refer to the examples folder to see how to use the router, along with usage of grouping and filters.

Installation

From the command line:

composer require alejoluc/via

Or write manually in composer.json:

{
  "require": {
    "alejoluc/via": "*"
  }
}

Using the "Facade"

A "Facade" is provided for those that want clearer code and don't mind using static classes here and there. You can use any method of the Router class when calling the Facade.

<?php
use alejoluc\Via\RouterFacade as Router;

// [Set up Router (see file in examples) 

Router::get('login', ['LoginController', 'showForm']);
Router::group('admin/', function(){
    Router::get('createUser', ['UsersController', 'createForm']);
}, ['isLoggedIn']);

Match Handlers

There are three possible scenarios when calling the dispatch() method: no route will match, or a route will match but some or all filters will fail, or a route will match and no filter fails.

In all cases, a Match object is passed to whatever match handler or handlers you have set up. You can see the src/SampleHandlers/ folder for several comprehensive handlers.

Letting the router build the request string on it's own or using setRequestString()

If no request string is manually specified, the router will try to get it automatically from $_SERVER['REQUEST_URI'] or $_SERVER['PATH_INFO']. Aditionally, it will truncate the script file name from the request string, if it is there, and it will also truncate the query string (anything after ? or &), if it exists. This will not happen if you manually set the request string via Router::setRequestString()

As a general rule, you should manually call Router::setRequestString() only when you know what you are doing and why, and let the router do the dirty work the rest of the time.

For example, if you have no url rewriting in place in your server, you might still want to use the router and you can do it by placing the routes in a query variable, like q. An example for that approach, assuming the file name is index.php, would be:

<?php
use alejoluc\Router\Router;
$router = new Router();
$q = isset($_GET['q']) ? $_GET['q'] : '/';
$router->setRequestString($q);

$router->get('/about', 'About Page'); // Will respond to /index.php?q=/about 

alejoluc/via 适用场景与选型建议

alejoluc/via 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 06 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-28