A PSR-17 adapter for php-http/message-factory
This package provides all implementations of the PSR-18 except for Psr\Http\Message\ServerRequestFactoryInterface
and Psr\Http\Message\UploadedFileFactoryInterface
because the
php-http/message-factory package do not have similar factories
PHP 7.0 or above.
$ composer require mjelamanov/psr17-httplug
use Mjelamanov\Psr17Httplug\RequestFactory;
use Http\Message\MessageFactory\GuzzleMessageFactory; // A php-http's request factory implementation
$requestFactory = new RequestFactory(new GuzzleMessageFactory());
$request = $requestFactory->createRequest('GET', 'http://example.com');
use Mjelamanov\Psr17Httplug\StreamFactory;
use Http\Message\StreamFactory\GuzzleStreamFactory; // A php-http's stream factory implementation
$streamFactory = new StreamFactory(new GuzzleStreamFactory());
// Create from string
$stream = $streamFactory->createStream(json_encode(['test' => true]));
// Create from resource
$stream = $streamFactory->createStreamFromResource(fopen('path/to/file', 'r'));
// Create from file
$stream = $streamFactory->createStreamFromFile('path/to/file', 'r');
use Mjelamanov\Psr17Httplug\UriFactory;
use Http\Message\StreamFactory\GuzzleUriFactory; // A php-http's uri factory implementation
$uriFactory = new UriFactory(new GuzzleUriFactory());
$uri = $uriFactory->createUri('http://example.com');
use Mjelamanov\Psr17Httplug\ResponseFactory;
use Http\Message\StreamFactory\GuzzleMessageFactory; // A php-http's response factory implementation
$responseFactory = new ResponseFactory(new GuzzleMessageFactory());
$response = $responseFactory->createResponse(200, 'OK');
composer test
The MIT license. Read LICENSE file.