stratify/http 问题修复 & 功能扩展

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

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

stratify/http

最新稳定版本:0.6.0

Composer 安装命令:

composer require stratify/http

包简介

HTTP middlewares for PSR-7 and PSR-15

README 文档

README

HTTP middleware utilities built upon:

composer require stratify/http

Middlewares

A middleware can be either an instance of Psr\Http\Server\MiddlewareInterface:

class MyMiddleware implements \Psr\Http\Server\MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
    {
        return new Response(...);
    }
}

$middleware = new MyMiddleware;

or a simple callable, which allows to use closures for quickly writing middlewares:

$middleware = function(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface {
    return new Response(...);
}

Middleware pipe

The middleware pipe let us pipe middlewares to execute one after the other. It is similar to using the pipe (|) operator on the command line.

It's interesting to note that the pipe is also a middleware, which means it can be nested or combined with any other middleware.

Usage:

$middleware = new Pipe([
    new Middleware1,
    new Middleware2,
    // ...
]);

// Run
$response = $middleware->process($request, $handler);

The pipe will first execute Middleware1. If that middleware calls $next then Middleware2 will be executed. An infinite number of middlewares can be piped together.

If you don't need to use the $handler argument for the pipe, you can use the LastHandler class:

$response = $middleware->process($request, new \Stratify\Http\Middleware\LastHandler);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-25