xoops/frame 问题修复 & 功能扩展

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

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

xoops/frame

Composer 安装命令:

composer require xoops/frame

包简介

XOOPS PSR-15 Middleware Dispatcher

README 文档

README

Frame implements a simple PSR-15 compatible middleware dispatcher.

Frame is composer managed, so the easiest way to install it is to require xoops/frame.

Software License Coverage Status Quality Score Latest Version

Xoops/Frame/Rack

Rack is a middleware dispatcher. Instances of Psr\Http\Server\MiddlewareInterface can be added to the rack. After the desired middlewares have been added, it is dispatched by passing a Psr\Http\Message\ServerRequestInterface object to the rack run() method.

$rack = new \Xoops\Frame\Rack();
$rack->add($someMiddleware);
$rack->add($anotherMiddleware);
$response = $rack->run($request);

Rack will invoke each middleware in the order it was added. Rack will pass itself to each middleware as the Psr\Http\Server\RequestHandlerInterface $handler parameter, and when called as such will dispatch the next middleware in its queue.

The racked middleware is expected to ultimately return a Psr\Http\Message\ResponseInterface object, and as per PSR-15, it will be returned from the run() invocation.

As an alternative to the run() method, you can depend on the __invoke() method to allow calling the Rack instance as a function.

$response = $rack($request);

A Rack instance is also a Psr\Http\Server\MiddlewareInterface object. This allows a Rack instance to be used as middleware, allowing a racks to be stacked.

Xoops/Frame/Exception

This namespace defines the following exceptions which can be thrown by Rack:

InvalidHandlerException

This results from either trying to add a Rack instance to itself as middleware, or from forcinging something other than a valid Psr\Http\Server\MiddlewareInterface object to the middleware queue.

RackExhaustedException

This exception results from attempting to advance past the end of the middleware queue. This condition indicates that no response message has been returned and there is no handler on the middleware queue to delegate response creation to.

Xoops\Frame\Panel

The Panel namespace contains several small rack panels that might be useful middleware in a duct tape sort of role.

Blank

Blank is just a placeholder. It does nothing other than delegate and return the response.

$rack->addToQueue(new Blank);

ClosureToMiddleware

ClosureToMiddleware lets you build middleware from a PHP Closure or anonymous function.

$callable = function (RequestInterface $request, RequestHandlerInterface $handler) {
    $response = $handler->handle($request);
    $modifiedResponse = $response->withHeader('X-Powered-By', 'black coffee');
    return $modifiedResponse;
};
$middleware = new ClosureToMiddleware($callable);

$rack->add($middleware);

FixedResponse

FixedResponse returns the Psr\Http\Message\ResponseInterface passed to it at instantiation.

$response = $myResponseFactory->createResponse(200);
$rack->add(new FixedResponse($response));

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2018-01-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固