1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Phiremock. |
4
|
|
|
* |
5
|
|
|
* Phiremock is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* Phiremock is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with Phiremock. If not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Mcustiel\Phiremock\Domain; |
20
|
|
|
|
21
|
|
|
use Mcustiel\Phiremock\Domain\Http\Body; |
22
|
|
|
use Mcustiel\Phiremock\Domain\Http\HeadersCollection; |
23
|
|
|
use Mcustiel\Phiremock\Domain\Http\StatusCode; |
24
|
|
|
use Mcustiel\Phiremock\Domain\Options\Delay; |
25
|
|
|
use Mcustiel\Phiremock\Domain\Options\ScenarioState; |
26
|
|
|
|
27
|
|
|
class HttpResponse extends Response |
28
|
|
|
{ |
29
|
|
|
/** @var StatusCode */ |
30
|
|
|
private $statusCode; |
31
|
|
|
|
32
|
|
|
/** @var Body */ |
33
|
|
|
private $body; |
34
|
|
|
|
35
|
|
|
/** @var HeadersCollection */ |
36
|
|
|
private $headers; |
37
|
|
|
|
38
|
75 |
|
public function __construct( |
39
|
|
|
?StatusCode $statusCode = null, |
40
|
|
|
?Body $body = null, |
41
|
|
|
?HeadersCollection $headers = null, |
42
|
|
|
?Delay $delayMillis = null, |
43
|
|
|
?ScenarioState $newScenarioState = null |
44
|
|
|
) { |
45
|
75 |
|
parent::__construct($delayMillis, $newScenarioState); |
46
|
75 |
|
$this->statusCode = $statusCode ?? StatusCode::createDefault(); |
47
|
75 |
|
$this->headers = $headers; |
48
|
75 |
|
$this->body = $body; |
49
|
75 |
|
} |
50
|
|
|
|
51
|
|
|
public static function createEmpty(): self |
52
|
|
|
{ |
53
|
|
|
return new self( |
54
|
|
|
new StatusCode(200), |
55
|
|
|
new Body(''), |
56
|
|
|
new HeadersCollection() |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
39 |
|
public function getStatusCode(): StatusCode |
61
|
|
|
{ |
62
|
39 |
|
return $this->statusCode; |
63
|
|
|
} |
64
|
|
|
|
65
|
3 |
|
public function hasBody(): bool |
66
|
|
|
{ |
67
|
3 |
|
return $this->body !== null; |
68
|
|
|
} |
69
|
|
|
|
70
|
36 |
|
public function getBody(): ?Body |
71
|
|
|
{ |
72
|
36 |
|
return $this->body; |
73
|
|
|
} |
74
|
|
|
|
75
|
9 |
|
public function hasHeaders(): bool |
76
|
|
|
{ |
77
|
9 |
|
return $this->headers !== null && !$this->headers->isEmpty(); |
78
|
|
|
} |
79
|
|
|
|
80
|
36 |
|
public function getHeaders(): ?HeadersCollection |
81
|
|
|
{ |
82
|
36 |
|
return $this->headers; |
83
|
|
|
} |
84
|
|
|
|
85
|
27 |
|
public function isHttpResponse(): bool |
86
|
|
|
{ |
87
|
27 |
|
return true; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|