Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
22 / 22 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
Server | |
100.00% |
22 / 22 |
|
100.00% |
4 / 4 |
16 | |
100.00% |
1 / 1 |
getHost | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
getPort | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
getPath | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getQuery | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
header | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
echo | n/a |
0 / 0 |
n/a |
0 / 0 |
1 |
1 | <?php |
2 | |
3 | namespace Tal; |
4 | |
5 | /** |
6 | * Class Server |
7 | * |
8 | * @package Tal |
9 | * @author Thomas Flori <thflori@gmail.com> |
10 | */ |
11 | class Server |
12 | { |
13 | public static function getHost() |
14 | { |
15 | if (isset($_SERVER['HTTP_HOST'])) { |
16 | $hostHeaderParts = explode(':', $_SERVER['HTTP_HOST']); |
17 | return $hostHeaderParts[0]; |
18 | } |
19 | |
20 | if (isset($_SERVER['SERVER_NAME'])) { |
21 | return $_SERVER['SERVER_NAME']; |
22 | } |
23 | |
24 | if (isset($_SERVER['SERVER_ADDR'])) { |
25 | return $_SERVER['SERVER_ADDR']; |
26 | } |
27 | |
28 | return null; |
29 | } |
30 | |
31 | public static function getPort() |
32 | { |
33 | if (isset($_SERVER['HTTP_HOST']) && strpos($_SERVER['HTTP_HOST'], ':') !== false) { |
34 | return explode(':', $_SERVER['HTTP_HOST'])[1]; |
35 | } |
36 | |
37 | if (isset($_SERVER['SERVER_PORT'])) { |
38 | return $_SERVER['SERVER_PORT']; |
39 | } |
40 | |
41 | return null; |
42 | } |
43 | |
44 | public static function getPath() |
45 | { |
46 | if (isset($_SERVER['REQUEST_URI'])) { |
47 | $requestUriParts = explode('?', $_SERVER['REQUEST_URI']); |
48 | return $requestUriParts[0]; |
49 | } |
50 | |
51 | return null; |
52 | } |
53 | |
54 | public static function getQuery() |
55 | { |
56 | if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '?') !== false) { |
57 | return explode('?', $_SERVER['REQUEST_URI'])[1]; |
58 | } |
59 | |
60 | if (isset($_SERVER['QUERY_STRING'])) { |
61 | return $_SERVER['QUERY_STRING']; |
62 | } |
63 | |
64 | return null; |
65 | } |
66 | |
67 | /** |
68 | * Send a raw HTTP header |
69 | * |
70 | * @link http://php.net/manual/en/function.header.php |
71 | * @param string $string The header string |
72 | * @param bool $replace |
73 | * @param int $responseCode |
74 | * @return void |
75 | * @codeCoverageIgnore trivial wrapper |
76 | */ |
77 | public function header($string, $replace = true, $responseCode = null) |
78 | { |
79 | header($string, $replace, $responseCode); |
80 | } |
81 | |
82 | /** |
83 | * Echos the given $string |
84 | * |
85 | * @param $string |
86 | * @return void |
87 | * @codeCoverageIgnore trivial wrapper |
88 | */ |
89 | public function echo($string) |
90 | { |
91 | echo($string); |
92 | } |
93 | } |