定制 idiosyncratic/http-router 二次开发

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

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

idiosyncratic/http-router

Composer 安装命令:

composer require idiosyncratic/http-router

包简介

A lightweight PSR-15 based HTTP router implementation

README 文档

README

A lightweight PSR-15 HTTP router implementation.

Installation

Use Composer:

composer require idiosyncratic/http-router

Usage

Idiosyncratic\Http\Router\Router implementing the PSR-15 Psr\Http\Server\RequestHandlerInterface is the main class. It has two dependencies:

  • An implementation of Idiosyncratic\Http\Router\RouteCollection, a collection of routes implementing a single method:
    /**
     * @throws Idiosyncratic\Http\Exception\Client\NotFound
     * @throws Idiosyncratic\Http\Exception\Client\MethodNotAllowed
     */
    public function findRoute(ServerRequestInterface $request) : Idiosyncratic\Http\Router\Route;
  • Psr\Container\ContainerInterface, responsible for retrieving the handler for the matched route.

Also included is Idiosyncratic\Http\Router\RouteGroup, a basic implementation of the RouteCollection interface based on FastRoute. The interface for defining routes is nearly identical to FastRoute's, with two notable exceptions:

  • The argument order for RouteGroup::addRoute is different. Route methods are defined last as string parameters.
  • The route handler must be the name of a class implementing Psr\Http\Server\RequestHandlerInterface.

Basic usage of the library (using the PHP League Container):

$container = new League\Container\Container();

$container->add(ServerRequestInterfaceImplementation::class);

$routes = new Idiosyncratic\Http\Router\RouteGroup();

$routes->addRoute('/hello', ServerRequestInterfaceImplementation::class, 'GET', 'POST');

$router = new Idiosyncratic\Http\Router\Router($routes, $container);

// Create instance of Psr\Http\Message\ServerRequestInterface...

$response = $router->handle($serverRequest);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: ISC
  • 更新时间: 2019-11-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固