Skip to content

mjelamanov/psr17-httplug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PSR-17 adapter for httplug's message factory

Build Status StyleCI

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.

About

A PSR-17 adapter for httplug's message factory

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages