codeinc/psr7-response-sender

此包已被废弃且不再维护。未建议替代包。

Code Inc. PSR-7 响应发送器

1.3.2 2018-09-24 06:37 UTC

This package is auto-updated.

Last update: 2020-02-04 11:48:23 UTC


README

此库是PHP 7编写的codeinc/router的配套库。它提供了发送ResponseSender响应到网页浏览器的响应发送器,并为PSR-7响应发送器提供了接口ResponseSenderInterface

响应发送器可以发送实现PSR-7 ResponseInterface的任何内容。

使用方法

<?php
use CodeInc\PSR7ResponseSender\ResponseSender;
use GuzzleHttp\Psr7\Response;

// a response can be anything implementing ResponseInterface, here the Guzzle implementation
$response = new Response();

// sends the response to the web browser
$sender = new ResponseSender();
$sender->send($response);

默认情况下,ResponseSender会移除所有PHP原生HTTP头。您可以通过布尔构造函数操作符或使用removePhpHttpHeaders()sendPhpHttpHeaders()方法来更改此行为。

还提供了一个名为GzResponseSender的第二个类,用于通过ob_start()ob_gzhandler()发送gzip压缩的响应。

安装

此库通过Packagist提供,并可以使用Composer进行安装。

composer require codeinc/psr7-response-sender

许可

此库在MIT许可下发布(见LICENSE文件)。