Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
Header | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
addHeader | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setHeader | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
addLogHeader | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | namespace WebPConvert\Serve; |
3 | |
4 | /** |
5 | * Add / Set HTTP header. |
6 | * |
7 | * This class does nothing more than adding two convenience functions for calling the "header" function. |
8 | * |
9 | * @package WebPConvert |
10 | * @author Bjørn Rosell <it@rosell.dk> |
11 | * @since Class available since Release 2.0.0 |
12 | */ |
13 | class Header |
14 | { |
15 | /** |
16 | * Convenience function for adding header (append). |
17 | * |
18 | * @param string $header The header to add. |
19 | * @return void |
20 | */ |
21 | public static function addHeader($header) |
22 | { |
23 | header($header, false); |
24 | } |
25 | |
26 | /** |
27 | * Convenience function for replacing header. |
28 | * |
29 | * @param string $header The header to set. |
30 | * @return void |
31 | */ |
32 | public static function setHeader($header) |
33 | { |
34 | header($header, true); |
35 | } |
36 | |
37 | /** |
38 | * Add log header and optionally send it to a logger as well. |
39 | * |
40 | * @param string $msg Message to add to "X-WebP-Convert-Log" header |
41 | * @param \WebPConvert\Loggers\BaseLogger $logger (optional) |
42 | * @return void |
43 | */ |
44 | public static function addLogHeader($msg, $logger = null) |
45 | { |
46 | self::addHeader('X-WebP-Convert-Log: ' . $msg); |
47 | if (!is_null($logger)) { |
48 | $logger->logLn($msg); |
49 | } |
50 | } |
51 | } |