Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
HttpResponse | |
100.00% |
13 / 13 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
hasHeader | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
hasHeaderValue | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | namespace HtaccessCapabilityTester; |
4 | |
5 | /** |
6 | * Class for holding properties of a HttpResponse |
7 | * |
8 | * @package HtaccessCapabilityTester |
9 | * @author Bjørn Rosell <it@rosell.dk> |
10 | * @since Class available since 0.7 |
11 | */ |
12 | class HttpResponse |
13 | { |
14 | |
15 | /* @var string the body of the response */ |
16 | public $body; |
17 | |
18 | /* @var string the status code of the response */ |
19 | public $statusCode; |
20 | |
21 | /* @var array the response headers keyed by lowercased field name */ |
22 | public $headersMapLowerCase; |
23 | |
24 | /** |
25 | * Constructor. |
26 | * |
27 | * @param string $body |
28 | * @param string $statusCode |
29 | * @param array $headersMap Map of headers, keyed by field name. |
30 | * There is only one value (string) for each key. |
31 | * If there are multiple values, they must be separated by comma |
32 | * |
33 | * @return void |
34 | */ |
35 | public function __construct($body, $statusCode, $headersMap) |
36 | { |
37 | $this->body = $body; |
38 | $this->statusCode = $statusCode; |
39 | $this->headersMapLowerCase = array_change_key_case($headersMap, CASE_LOWER); |
40 | } |
41 | |
42 | /** |
43 | * Check if the response has a header |
44 | * |
45 | * @param string $fieldName |
46 | * @return bool |
47 | */ |
48 | public function hasHeader($fieldName) |
49 | { |
50 | $fieldName = strtolower($fieldName); |
51 | return (isset($this->headersMapLowerCase[$fieldName])); |
52 | } |
53 | |
54 | /** |
55 | * Check if the response has a header with a given value |
56 | * |
57 | * @param string $fieldName |
58 | * @param string $fieldValue |
59 | * @return bool |
60 | */ |
61 | public function hasHeaderValue($fieldName, $fieldValue) |
62 | { |
63 | $fieldName = strtolower($fieldName); |
64 | if (!isset($this->headersMapLowerCase[$fieldName])) { |
65 | return false; |
66 | } |
67 | $values = explode(',', $this->headersMapLowerCase[$fieldName]); |
68 | foreach ($values as $value) { |
69 | if (trim($value) == $fieldValue) { |
70 | return true; |
71 | } |
72 | } |
73 | return false; |
74 | } |
75 | } |