Skip to content

Instantly share code, notes, and snippets.

@ovr
Created July 14, 2019 10:52
Show Gist options
  • Save ovr/49fc7876204f762f4954666fa8138cd5 to your computer and use it in GitHub Desktop.
Save ovr/49fc7876204f762f4954666fa8138cd5 to your computer and use it in GitHub Desktop.
Combining RequestFactoryInterface, StreamFactoryInterface from PSR-17
<?php
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;
class HttpStack implements RequestFactoryInterface, StreamFactoryInterface
{
/**
* @var RequestFactoryInterface
*/
protected $requestFactory;
/**
* @var StreamFactoryInterface
*/
protected $streamFactory;
/**
* HttpStack constructor.
* @param RequestFactoryInterface $requestFactory
* @param StreamFactoryInterface $streamFactory
*/
public function __construct(RequestFactoryInterface $requestFactory, StreamFactoryInterface $streamFactory)
{
$this->requestFactory = $requestFactory;
$this->streamFactory = $streamFactory;
}
/**
* {@inheritDoc}
*/
public function createRequest(string $method, $uri): RequestInterface
{
return $this->requestFactory->createRequest($method, $uri);
}
/**
* {@inheritDoc}
*/
public function createStream(string $content = ''): StreamInterface
{
return $this->streamFactory->createStream($content);
}
/**
* {@inheritDoc}
*/
public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
{
return $this->streamFactory->createStreamFromFile($filename, $mode);
}
/**
* {@inheritDoc}
*/
public function createStreamFromResource($resource): StreamInterface
{
return $this->streamFactory->createStreamFromResource($resource);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment