Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
4 / 5 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| HeaderAbstract | |
80.00% |
4 / 5 |
|
75.00% |
3 / 4 |
5.20 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| lock | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isLocked | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| generate | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getProtocolVersion | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| set | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| get | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| has | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getRequestTime | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| push | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Message |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Message; |
| 16 | |
| 17 | use phpOMS\Localization\Localization; |
| 18 | |
| 19 | /** |
| 20 | * Response class. |
| 21 | * |
| 22 | * @package phpOMS\Message |
| 23 | * @license OMS License 2.0 |
| 24 | * @link https://jingga.app |
| 25 | * @since 1.0.0 |
| 26 | */ |
| 27 | abstract class HeaderAbstract |
| 28 | { |
| 29 | /** |
| 30 | * Responses. |
| 31 | * |
| 32 | * @var bool |
| 33 | * @since 1.0.0 |
| 34 | */ |
| 35 | protected bool $isLocked = false; |
| 36 | |
| 37 | /** |
| 38 | * Localization. |
| 39 | * |
| 40 | * @var Localization |
| 41 | * @since 1.0.0 |
| 42 | */ |
| 43 | public Localization $l11n; |
| 44 | |
| 45 | /** |
| 46 | * Account. |
| 47 | * |
| 48 | * @var int |
| 49 | * @since 1.0.0 |
| 50 | */ |
| 51 | public int $account = 0; |
| 52 | |
| 53 | /** |
| 54 | * Response status. |
| 55 | * |
| 56 | * @var int |
| 57 | * @since 1.0.0 |
| 58 | */ |
| 59 | public int $status = 0; |
| 60 | |
| 61 | /** |
| 62 | * Response timestamp. |
| 63 | * |
| 64 | * @var int |
| 65 | * @since 1.0.0 |
| 66 | */ |
| 67 | public int $timestamp = 0; |
| 68 | |
| 69 | /** |
| 70 | * Constructor. |
| 71 | * |
| 72 | * @since 1.0.0 |
| 73 | */ |
| 74 | public function __construct() |
| 75 | { |
| 76 | $this->l11n = new Localization(); |
| 77 | $this->timestamp = \time(); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Set header locked. |
| 82 | * |
| 83 | * @return void |
| 84 | * |
| 85 | * @since 1.0.0 |
| 86 | */ |
| 87 | public function lock() : void |
| 88 | { |
| 89 | $this->isLocked = true; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Is header locked? |
| 94 | * |
| 95 | * @return bool |
| 96 | * |
| 97 | * @since 1.0.0 |
| 98 | */ |
| 99 | public function isLocked() : bool |
| 100 | { |
| 101 | return $this->isLocked; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Generate header based on status code. |
| 106 | * |
| 107 | * @param int $statusCode Status code |
| 108 | * |
| 109 | * @return void |
| 110 | * |
| 111 | * @since 1.0.0 |
| 112 | */ |
| 113 | abstract public function generate(int $statusCode) : void; |
| 114 | |
| 115 | /** |
| 116 | * Get protocol version. |
| 117 | * |
| 118 | * @return string |
| 119 | * |
| 120 | * @since 1.0.0 |
| 121 | */ |
| 122 | abstract public function getProtocolVersion() : string; |
| 123 | |
| 124 | /** |
| 125 | * Set header. |
| 126 | * |
| 127 | * @param string $key Header key |
| 128 | * @param string $value Header value |
| 129 | * @param bool $overwrite Overwrite if key already exists |
| 130 | * |
| 131 | * @return bool |
| 132 | * |
| 133 | * @since 1.0.0 |
| 134 | */ |
| 135 | abstract public function set(string $key, string $value, bool $overwrite = false) : bool; |
| 136 | |
| 137 | /** |
| 138 | * Get header by key. |
| 139 | * |
| 140 | * @param null|string $key Header key |
| 141 | * |
| 142 | * @return array |
| 143 | * |
| 144 | * @since 1.0.0 |
| 145 | */ |
| 146 | abstract public function get(string $key = null) : array; |
| 147 | |
| 148 | /** |
| 149 | * Header has key? |
| 150 | * |
| 151 | * @param string $key Header key |
| 152 | * |
| 153 | * @return bool |
| 154 | * |
| 155 | * @since 1.0.0 |
| 156 | */ |
| 157 | abstract public function has(string $key) : bool; |
| 158 | |
| 159 | /** |
| 160 | * Get time of the request |
| 161 | * |
| 162 | * @return int |
| 163 | * |
| 164 | * @since 1.0.0 |
| 165 | */ |
| 166 | public function getRequestTime() : int |
| 167 | { |
| 168 | return $this->timestamp; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Push all headers. |
| 173 | * |
| 174 | * @return void |
| 175 | * |
| 176 | * @since 1.0.0 |
| 177 | * @codeCoverageIgnore |
| 178 | */ |
| 179 | public function push() : void |
| 180 | { |
| 181 | } |
| 182 | } |