承接 ajgarlag/psr15-router 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ajgarlag/psr15-router

最新稳定版本:0.5.3

Composer 安装命令:

composer create-project ajgarlag/psr15-router

包简介

Component to route PSR-7 requests through PSR-15 middlewares

README 文档

README

The Psr15 Router component allows you to route PSR-7 requests through PSR-15 middlewares.

Build Status Latest Stable Version Latest Unstable Version Total Downloads Montly Downloads Daily Downloads License

Installation

To install the latest stable version of this component, open a console and execute the following command:

$ composer require ajgarlag/psr15-router

Usage

You can choose if you want to route your request through a MiddlewareInterface or a RequestHandlerInterface

Middleware routing

With this option, you has to build a Router to discriminate which middleware will process the request. Then build RouterMiddleware to process the request:

use Ajgarlag\Psr15\Router\Matcher\UriRegexRequestMatcher;
use Ajgarlag\Psr15\Router\Middleware\Route;
use Ajgarlag\Psr15\Router\Middleware\ArrayRouter;
use Ajgarlag\Psr15\Router\Middleware\RouterMiddleware;

$userMiddleware; //Some middleware to process user requests
$userRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/user/'),
    $userMiddleware
);
$adminMiddleware; //Some middleware to process admin requests
$adminRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/admin/'),
    $adminMiddleware
);

$router = new ArrayRouter();
$router->addRoute($userRoute);
$router->addRoute($adminRoute);

$routerMiddleware = new RouterMiddleware($router);

$response = $routerMiddleware->process($request, $requestHandler);

If the router does not return any middleware to process the request, it is processed directly through the request handler.

Request handler routing

With this option, you has to build a Router to discriminate which request handler will process the request. Then build RouterRequestHandler to process the request. A failover request handler is required to process the request if the router cannot route the request. Usually this failover request handler should return a 404 response.

use Ajgarlag\Psr15\Router\Matcher\UriRegexRequestMatcher;
use Ajgarlag\Psr15\Router\RequestHandler\Route;
use Ajgarlag\Psr15\Router\RequestHandler\ArrayRouter;
use Ajgarlag\Psr15\Router\RequestHandler\RouterRequestHandler;

$userRequestHandler; //Some request handler to process user requests
$userRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/user/'),
    $userRequestHandler
);
$adminRequestHandler; //Some request handler to process admin requests
$adminRoute = new Route(
    new UriRegexRequestMatcher('^http(s)?://example.org/admin/'),
    $adminRequestHandler
);

$router = new ArrayRouter();
$router->addRoute($userRoute);
$router->addRoute($adminRoute);

$failoverRequestHandler; // Request handler that returns 404 unconditionally
$routerRequestHandler = new RouterRequestHandler($router, $failoverRequestHandler);

$response = $routerRequestHandler->handle($request);

License

This component is under the MIT license. See the complete license in the LICENSE file.

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker.

Author Information

Developed with ♥ by Antonio J. García Lagar.

If you find this component useful, please add a ★ in the GitHub repository page and/or the Packagist package page.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固