Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A super lightweight PSR-7 implementation

License

NotificationsYou must be signed in to change notification settings

Nyholm/psr7

Repository files navigation

Latest VersionTotal DownloadsMonthly DownloadsSoftware LicenseStatic analysisTests

A super lightweight PSR-7 implementation. Very strict and very fast.

DescriptionGuzzleLaminasSlimNyholm
Lines of code3.3003.1001.9001.000
PSR-7*66%100%75%100%
PSR-17NoYesYesYes
HTTPlugNoNoNoYes
Performance (runs per second)**14.55314.70313.41617.734

* Percent of completed tests inhttps://github.com/php-http/psr7-integration-tests

** Benchmark with 50.000 runs. Seehttps://github.com/devanych/psr-http-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 inthePSR-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

WithHTTPlug or any other PSR-18 (HTTP client) you may sendrequests 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

Thenyholm/psr7-server package can be usedto 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 laminas/laminas-httphandlerrunner
$psr17Factory =new \Nyholm\Psr7\Factory\Psr17Factory();$responseBody =$psr17Factory->createStream('Hello world');$response =$psr17Factory->createResponse(200)->withBody($responseBody);(new \Laminas\HttpHandlerRunner\Emitter\SapiEmitter())->emit($response);

Our goal

This package is currently maintained byTobias Nyholm andMartijn van der Ven. They have decided that thegoal of this library should be to provide a super strict implementation ofPSR-7 that is blazing fast.

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


[8]ページ先頭

©2009-2025 Movatter.jp