定制 minormous/dispatch 二次开发

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

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

minormous/dispatch

Composer 安装命令:

composer require minormous/dispatch

包简介

An HTTP Interop compatible middleware dispatcher

README 文档

README

Latest Stable Version License Build Status Code Coverage Scrutinizer Code Quality

An HTTP Interop compatible middleware dispatcher in Minormous. Attempts to be PSR-1, PSR-2, PSR-4, PSR-7, and PSR-15 compliant.

Heavily influenced by the design of Tari by ircmaxwell.

For more information, see the documentation.

Install

composer require minormous/dispatch

Usage

The MiddlewareCollection is a container for middleware that acts as the entry point. It takes two arguments:

  • An array of $middleware which must be instances of server middleware.
  • A callable $default that acts as the terminator for the collection and returns an empty response.

Once the collection is prepared it can dispatched with a server request and will return the response for output.

Example

use Minormous\Dispatch\MiddlewareCollection;

// Any implementation of PSR-15 MiddlewareInterface
$middleware = [
    new FooMiddleware(),
    // ...
];

// Default handler for end of collection
$default = function (ServerRequestInterface $request) {
    // Any implementation of PSR-7 ResponseInterface
    return new Response();
};

$collection = new MiddlewareCollection($middleware);

// Any implementation of PSR-7 ServerRequestInterface
$request = ServerRequest::fromGlobals();
$response = $collection->dispatch($request, $default);

Nested Collections

The MiddlewareCollection also implements the MiddlewareInterface to allow collections to be nested:

use Minormous\Dispatch\MiddlewareCollection;

// Any implementation of PSR-15 MiddlewareInterface
$middleware = [
    new FooMiddleware(),

    // A nested collection
    new MiddlewareCollection(...),

    // More middleware
    new BarMiddleware(),
    // ...
];

$collection = new MiddlewareCollection($middleware);

// HTTP factories can also be used
$default = [$responseFactory, 'createResponse'];
$request = $serverRequestFactory->createRequest($_SERVER);

$response = $collection->dispatch($request, $default);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-13