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
|
78 |
|
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
|
78 |
|
parent::__construct($delayMillis, $newScenarioState); |
46
|
78 |
|
$this->statusCode = $statusCode ?? StatusCode::createDefault(); |
47
|
78 |
|
$this->headers = $headers; |
48
|
78 |
|
$this->body = $body; |
49
|
78 |
|
} |
50
|
|
|
|
51
|
3 |
|
public static function createEmpty(): self |
52
|
|
|
{ |
53
|
3 |
|
return new self( |
54
|
3 |
|
new StatusCode(200), |
55
|
3 |
|
new Body('') |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
42 |
|
public function getStatusCode(): StatusCode |
60
|
|
|
{ |
61
|
42 |
|
return $this->statusCode; |
62
|
|
|
} |
63
|
|
|
|
64
|
3 |
|
public function hasBody(): bool |
65
|
|
|
{ |
66
|
3 |
|
return $this->body !== null; |
67
|
|
|
} |
68
|
|
|
|
69
|
39 |
|
public function getBody(): ?Body |
70
|
|
|
{ |
71
|
39 |
|
return $this->body; |
72
|
|
|
} |
73
|
|
|
|
74
|
12 |
|
public function hasHeaders(): bool |
75
|
|
|
{ |
76
|
12 |
|
return $this->headers !== null && !$this->headers->isEmpty(); |
77
|
|
|
} |
78
|
|
|
|
79
|
36 |
|
public function getHeaders(): ?HeadersCollection |
80
|
|
|
{ |
81
|
36 |
|
return $this->headers; |
82
|
|
|
} |
83
|
|
|
|
84
|
30 |
|
public function isHttpResponse(): bool |
85
|
|
|
{ |
86
|
30 |
|
return true; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|