ellipse/router-aura
Composer 安装命令:
composer require ellipse/router-aura
包简介
Aura router Psr-15 middleware and request handler
README 文档
README
Aura router Psr-15 middleware and request handler.
Require php >= 7.0
Installation composer require ellipse/router-aura
Run tests ./vendor/bin/kahlan
Usage as request handler
This package provides an Ellipse\Router\AuraRouterRequestHandler Psr-15 request handler taking an instance of Aura\Router\RouterContainer as parameter.
This aura router is expected to have a populated map or to have a map builder defined, usually using its ->setMapBuilder() method. The route handlers it matches are expected to be implementations of Psr\Http\Server\RequestHandlerInterface.
When the AuraRouterRequestHandler handles a request the aura router is used to match a Psr-15 request handler. When the matched route pattern contains placeholders, a new request is created with those placeholders => matched value pairs as request attributes. Finally the matched request handler is proxied with this new request to actually return a response.
Setting the aura router map builder using its ->setMapBuilder() method allows the time consuming task of mapping routes to be performed only when the request is handled with the AuraRouterRequestHandler. If for some reason an application handles the incoming request with another request handler, no time is lost mapping routes for this one.
Regarding exceptions:
- An
Ellipse\Router\Exceptions\MatchedHandlerTypeExceptionis thrown when the route handler matched by the aura router is not an implementation ofPsr\Http\Server\RequestHandlerInterface. - An
Ellipse\Router\Exceptions\NotFoundExceptionis thrown when no route match the url. - An
Ellipse\Router\Exceptions\MethodNotAllowedExceptionis thrown when a route matches the url but the request http method is not allowed by the matched route. - An
Ellipse\Router\Exceptions\AuraMatcherExceptionis thrown when any other aura router rule failed.
<?php namespace App; use Aura\Router\RouterContainer; use Ellipse\Router\AuraRouterRequestHandler; // Get a psr7 request. $request = some_psr7_request_factory(); // Create an aura router. $router = new RouterContainer; // Set the router map builder. $router->setMapBuilder(function ($map) { // The route handlers must be Psr-15 request handlers. $map->get('index', '/', new SomeRequestHandler); // When this route is matched a new request with an 'id' attribute would be passed to the request handler. $map->get('path', '/path/{id}', new SomeOtherRequestHandler); }); // Create an aura router request handler using this aura router. $handler = new AuraRouterRequestHandler($router); // Produce a response with the aura router request handler. $response = $handler->handle($request);
Usage as middleware
This package provides an Ellipse\Router\AuraRouterMiddleware Psr-15 middleware also taking an aura router as parameter.
Under the hood it creates a AuraRouterRequestHandler with the given aura router and use it to handle the request. When a NotFoundException is thrown, the request processing is delegated to the next middleware.
<?php namespace App; use Aura\Router\RouterContainer; use Ellipse\Router\AuraRouterMiddleware; // Get a psr7 request. $request = some_psr7_request_factory(); // Create an aura router. $router = new RouterContainer; // Set the router map builder. $router->setMapBuilder(function ($map) { // The route handlers must be Psr-15 request handlers. $map->get('index', '/', new SomeRequestHandler); // When this route is matched a new request with an 'id' attribute would be passed to the request handler. $map->get('path', '/path/{id}', new SomeOtherRequestHandler); }); // Create an aura router middleware using this aura router. $middleware = new AuraRouterMiddleware($router); // When a route is matched the request is handled by the matched request handler. // Otherwise NextRequestHandler is used to handle the request. $response = $middleware->process($request, new NextRequestHandler);
ellipse/router-aura 适用场景与选型建议
ellipse/router-aura 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 06 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「router」 「middleware」 「aura」 「psr-15」 「request-handler」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ellipse/router-aura 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ellipse/router-aura 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ellipse/router-aura 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Installs Aura packages to the Aura system "package" directory.
Middleware to use Aura.Router
PSR-11 Aura.DI container configurator for Laminas and Mezzio applications. Drop-in replacement for the archived laminas/laminas-auradi-config with PHP 8.4 and 8.5 support.
Router
Slim Framework 3 CSRF protection middleware utilities
统计信息
- 总下载量: 40
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-06-07