psr7

A super lightweight PSR-7 implementation

  • 所有者: Nyholm/psr7
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

PSR-7 implementation

Latest Version
Build Status
Code Coverage
Quality Score
Total Downloads
Monthly Downloads
Software License

A super lightweight PSR-7 implementation. Very strict and very fast., Description, Guzzle, Zend, Slim, Nyholm, ----, ------, ----, ----, ------, Lines of code, 3 000, 3 000, 1 700, 1 000, PHP7, No, Yes, No, Yes, PSR-7*, 66%, 100%, 75%, 100%, PSR-17, No, Yes, Yes, Yes, HTTPlug, No, No, No, Yes, Performance**, 1.34x, 1x, 1.16x, 1.75x, * Percent of completed tests in https://github.com/php-http/psr7-integration-tests

** See benchmark at https://github.com/Nyholm/http-client-benchmark (higher is better)

Installation

composer require nyholm/psr7

If you are using Symfony Flex then you get all message factories registered as services.

Usage

The PSR-7 objects do not contain any other public methods than those defined in
the PSR-7 specification.

Create objects

Use the PSR-17 factory to create requests, streams, URIs etc.

$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
$request = $psr17Factory->createRequest('GET', 'http://tnyholm.se');
$stream = $psr17Factory->createStream('foobar');

Sending a request

With HTTPlug or any other PSR-18 (HTTP client) you may send
requests like:

composer require kriswallsmith/buzz
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
$psr18Client = new \Buzz\Client\Curl($psr17Factory);

$request = $psr17Factory->createRequest('GET', 'http://tnyholm.se');
$response = $psr18Client->sendRequest($request);

Create server requests

The nyholm/psr7-server package can be used
to create server requests from PHP superglobals.

composer require nyholm/psr7-server
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();

$creator = new \Nyholm\Psr7Server\ServerRequestCreator(
    $psr17Factory, // ServerRequestFactory
    $psr17Factory, // UriFactory
    $psr17Factory, // UploadedFileFactory
    $psr17Factory  // StreamFactory
);

$serverRequest = $creator->fromGlobals();

Emitting a response

composer require zendframework/zend-httphandlerrunner
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();

$responseBody = $psr17Factory->createStream('Hello world');
$response = $psr17Factory->createResponse(200)->withBody($responseBody);
(new \Zend\HttpHandlerRunner\Emitter\SapiEmitter())->emit($response);

Our goal

This package is currently maintained by Tobias Nyholm and
Martijn van der Ven. They have decided that the
goal of this library should be to provide a super strict implementation of
PSR-7 that is blazing fast.

The package will never include any extra features nor helper methods. All our classes
and functions exist because they are required to fulfill the PSR-7 specification.

主要指标

概览
名称与所有者Nyholm/psr7
主编程语言PHP
编程语言PHP (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2016-07-13 10:59:54
推送于2024-09-09 07:07:02
最后一次提交2024-09-09 09:06:30
发布数24
最新版本名称1.8.2 (发布于 )
第一版名称0.1.0 (发布于 )
用户参与
星数1.2k
关注者数26
派生数74
提交数200
已启用问题?
问题数82
打开的问题数5
拉请求数150
打开的拉请求数0
关闭的拉请求数28
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?