mjelamanov / psr17-httplug
A PSR-17 adapter for httplug's message factory
1.1.1
2021-11-07 13:15 UTC
Requires
- php: >=7.0
- php-http/message-factory: ^1.0
- psr/http-factory: ^1.0
Requires (Dev)
- guzzlehttp/psr7: ^1.5
- http-interop/http-factory-tests: >=0.5.0
- php-http/message: >=1.7
Provides
This package is auto-updated.
Last update: 2024-11-07 20:04:30 UTC
README
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
Requirements
PHP 7.0 or above.
Installation
$ composer require mjelamanov/psr17-httplug
RequestFactory
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');
StreamFactory
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');
UriFactory
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');
ResponseFactory
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');
Test
composer test
License
The MIT license. Read LICENSE file.