tailored-tunes/php-router 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tailored-tunes/php-router

最新稳定版本:2.0.2

Composer 安装命令:

composer require tailored-tunes/php-router

包简介

A lightweight router solution

关键字:

README 文档

README

A small routing library for php that decouples controllers from routing. The routing table only acts as a translation table between paths and intentions.

Installation

Install via composer. Installation help and versions at Packagist

Usage

Set up routes

use TailoredTunes\Router;

$router = new Router();
$router->addRoutes(
	[
		["/" => "Home#index"],
		["/login" => "Home#login"],
		["/logout" => "Home#logout"],
		["/privacy" => "Home#privacy"],
		["/magic/:var1/:var2" => "Home#magic"]
    ]
);

Variables in paths

You can match path variables by adding :var notions to the route table, as above. Those parameters will translate to the respective variable name in the parameters array of the handler.

Handle routes

The reason behind not handling the request internally is that you might want to put a controller factory between the routing and the serving. This way the router only tells you what the intention of the route was, then it's up to you to map it to a controller.

// $uri = the request uri
// $method = the request method
// $params = parameters for the request.

$requestParamBuilder = new RequestParamBuilder();
$requestParamBuilder->withEnv($_ENV)
	->withRequest($_REQUEST)
	->withCookies($_COOKIE)
	->withFiles($_FILES)
	->withServer($_SERVER)
	->withSession($_SESSION);

$params = new RequestParams($requestParamBuilder);

$handler = $router->handle($uri, $method, $params);

// serve request
call_user_func_array(array($handler->controller(), $handler->action()), $handler->parameters());

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-10-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固