binsoul/net-http-response
Composer 安装命令:
composer require binsoul/net-http-response
包简介
Specialized response and body classes plus response emitter
关键字:
README 文档
README
Install
Via composer:
$ composer require binsoul/net-http-response
This package provides PSR-7 ResponseInterface compatible response classes specialized for known HTTP status codes and body implementations which extend the PSR-7 StreamInterface with some useful methods. The included response emitter can output responses to different target environments.
Usage
Output a text response on a web server:
<?php use BinSoul\Net\Http\Response\Body\Type\TextBody; use BinSoul\Net\Http\Response\Emitter\DefaultEmitter; use BinSoul\Net\Http\Response\Emitter\Target\SapiTarget; use BinSoul\Net\Http\Response\Type\Success\OkResponse; require 'vendor/autoload.php'; $response = new OkResponse(new TextBody('Hello world!')); $emitter = new DefaultEmitter(); $emitter->emit($response, new SapiTarget());
Capture and display response headers and body:
<?php use BinSoul\Net\Http\Response\Body\Type\TextBody; use BinSoul\Net\Http\Response\Emitter\DefaultEmitter; use BinSoul\Net\Http\Response\Emitter\Target\CaptureTarget; use BinSoul\Net\Http\Response\Type\Success\OkResponse; require 'vendor/autoload.php'; // make var_export HTML friendly function dump($value) { return htmlentities(preg_replace("/\s+=>\s+/m", ' => ', var_export($value, true))); } $response = new OkResponse(new TextBody('Hello world!')); $target = new CaptureTarget(); $emitter = new DefaultEmitter(); $emitter->emit($response, $target); ?> <!DOCTYPE html> <html> <body> <h1>Headers</h1> <pre><?= dump($target->getHeaders()) ?></pre> <h1>Body</h1> <pre><?= dump($target->getBody()) ?></pre> </body> </html>
Testing
$ composer test
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-21