|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Http\Message\Psr17; |
| 4 | + |
| 5 | +use Psr\Http\Message\RequestFactoryInterface; |
| 6 | +use Psr\Http\Message\ResponseFactoryInterface; |
| 7 | +use Psr\Http\Message\StreamFactoryInterface; |
| 8 | + |
| 9 | +/** |
| 10 | + * Compatibility layer for PSR-17 reqeust and response factory. |
| 11 | + * |
| 12 | + * @author Márk Sági-Kazár <[email protected]> |
| 13 | + */ |
| 14 | +final class MessageFactory implements \Http\Message\MessageFactory |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var \Http\Message\ResponseFactory |
| 18 | + */ |
| 19 | + private $requestFactory; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \Http\Message\ResponseFactory |
| 23 | + */ |
| 24 | + private $responseFactory; |
| 25 | + |
| 26 | + public function __construct( |
| 27 | + RequestFactoryInterface $requestFactory, |
| 28 | + ResponseFactoryInterface $responseFactory, |
| 29 | + StreamFactoryInterface $streamFactory |
| 30 | + ) { |
| 31 | + $this->requestFactory = new RequestFactory($requestFactory, $streamFactory); |
| 32 | + $this->responseFactory = new ResponseFactory($responseFactory, $streamFactory); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * {@inheritdoc} |
| 37 | + */ |
| 38 | + public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1') |
| 39 | + { |
| 40 | + return $this->requestFactory->createRequest($method, $uri, $headers, $body, $protocolVersion); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * {@inheritdoc} |
| 45 | + */ |
| 46 | + public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $protocolVersion = '1.1') |
| 47 | + { |
| 48 | + return $this->responseFactory->createResponse($statusCode, $reasonPhrase, $headers, $body, $protocolVersion); |
| 49 | + } |
| 50 | +} |
0 commit comments