-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomResponseFactory.php
48 lines (40 loc) · 1.13 KB
/
CustomResponseFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace HttpSoft\Basis\Response;
use HttpSoft\Message\Response;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
final class CustomResponseFactory implements ResponseFactoryInterface
{
/**
* @var array
*/
private array $headers;
/**
* @var StreamInterface|string|resource
*/
private $body;
/**
* @var string
*/
private string $protocol;
/**
* @param array|null $headers
* @param StreamInterface|string|resource $body
* @param string $protocol
*/
public function __construct(array $headers = null, $body = 'php://temp', string $protocol = '1.1')
{
$this->headers = $headers ?? ['Content-Type' => 'text/html; charset=UTF-8'];
$this->body = $body;
$this->protocol = $protocol;
}
/**
* {@inheritDoc}
*/
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
{
return new Response($code, $this->headers, $this->body, $this->protocol, $reasonPhrase);
}
}