Total Complexity | 7 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | trait Header |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * Request headers |
||
26 | * @var array |
||
27 | */ |
||
28 | private static $__headers = []; |
||
29 | |||
30 | /** |
||
31 | * Checks the request header existence by given key |
||
32 | * @param string $key |
||
33 | * @return bool |
||
34 | */ |
||
35 | public static function hasHeader(string $key): bool |
||
36 | { |
||
37 | return isset(self::$__headers[strtolower($key)]); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Gets the request header by given key |
||
42 | * @param string $key |
||
43 | * @return string|null |
||
44 | */ |
||
45 | public static function getHeader(string $key): ?string |
||
46 | { |
||
47 | return self::hasHeader($key) ? self::$__headers[strtolower($key)] : null; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Sets the request header |
||
52 | * @param string $key |
||
53 | * @param mixed $value |
||
54 | */ |
||
55 | public static function setHeader(string $key, $value) |
||
56 | { |
||
57 | self::$__headers[strtolower($key)] = $value; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Gets all request headers |
||
62 | * @return array |
||
63 | */ |
||
64 | public static function allHeaders(): array |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Deletes the header by given key |
||
71 | * @param string $key |
||
72 | */ |
||
73 | public static function deleteHeader(string $key) |
||
80 | } |