summaryrefslogtreecommitdiffstats
path: root/library/vendor/iplx/Http/Response.php
blob: 25448b1254ae2b365ecedd59c1a49bdf5eff55c0 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

namespace iplx\Http;

use Psr\Http\Message\ResponseInterface;

/**
 * A HTTP response
 */
class Response implements ResponseInterface
{
    use MessageTrait;

    /**
     * Status code of the response
     *
     * @var int
     */
    protected $statusCode;

    /**
     * Response status reason phrase
     *
     * @var string
     */
    protected $reasonPhrase = '';

    /**
     * Create a new HTTP response
     *
     * @param   int     $statusCode         Response status code
     * @param   array   $headers            Response headers
     * @param   string  $body               Response body
     * @param   string  $protocolVersion    Protocol version
     * @param   string  $reasonPhrase       Response status reason phrase
     */
    public function __construct($statusCode = 200, array $headers = [], $body = null, $protocolVersion = '1.1', $reasonPhrase = '')
    {
        $this->statusCode = $statusCode;
        $this->setHeaders($headers);
        $this->body = Stream::create($body);
        $this->protocolVersion = $protocolVersion;
        $this->reasonPhrase = $reasonPhrase;
    }

    public function getStatusCode()
    {
        return $this->statusCode;
    }

    public function withStatus($code, $reasonPhrase = '')
    {
        $response = clone $this;
        $response->statusCode = $code;
        $response->reasonPhrase = $reasonPhrase;

        return $response;
    }

    public function getReasonPhrase()
    {
        return $this->reasonPhrase;
    }
}