sunrise/http-message

Sunrise HTTP message wrapper for PHP 7.1+ based on RFC-7230, PSR-7 & PSR-17

v1.4.0 2020-12-26 06:03 UTC

README

Gitter Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads License

Awards

SymfonyInsight

Installation

composer require sunrise/http-message

How to use?

HTTP Request Message

use Sunrise\Http\Message\RequestFactory;

$message = (new RequestFactory)->createRequest('GET', 'http://php.net/');

// just use PSR-7 methods...

HTTP Response Message

use Sunrise\Http\Message\ResponseFactory;

$message = (new ResponseFactory)->createResponse(200, 'OK');

// just use PSR-7 methods...

Using headers as objects

Please note that this isn't related to the PSR-7...

composer require sunrise/http-header-kit
use Sunrise\Http\Header\HeaderLastModified;

$header = new HeaderLastModified(new \DateTime('1 day ago'));

$response = $response->withHeaderObject($header);
use Sunrise\Http\Header\HeaderCollection;
use Sunrise\Http\Header\HeaderContentLength;
use Sunrise\Http\Header\HeaderContentType;

$headers = new HeaderCollection([
    new HeaderContentLength(1024),
    new HeaderContentType('application/jpeg'),
]);

$response = $response->withHeaderCollection($headers);

Related PSR-7 packages

Test run

php vendor/bin/phpunit

Useful links