|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Safe; |
| 4 | + |
| 5 | +use Safe\Exceptions\ApacheException; |
| 6 | + |
| 7 | +/** |
| 8 | + * Fetch the Apache version. |
| 9 | + * |
| 10 | + * @return string Returns the Apache version on success. |
| 11 | + * @throws ApacheException |
| 12 | + * |
| 13 | + */ |
| 14 | +function apache_get_version(): string |
| 15 | +{ |
| 16 | + error_clear_last(); |
| 17 | + $safeResult = \apache_get_version(); |
| 18 | + if ($safeResult === false) { |
| 19 | + throw ApacheException::createFromPhpError(); |
| 20 | + } |
| 21 | + return $safeResult; |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +/** |
| 26 | + * Retrieve an Apache environment variable specified by |
| 27 | + * variable. |
| 28 | + * |
| 29 | + * @param string $variable The Apache environment variable |
| 30 | + * @param bool $walk_to_top Whether to get the top-level variable available to all Apache layers. |
| 31 | + * @return string The value of the Apache environment variable on success |
| 32 | + * @throws ApacheException |
| 33 | + * |
| 34 | + */ |
| 35 | +function apache_getenv(string $variable, bool $walk_to_top = false): string |
| 36 | +{ |
| 37 | + error_clear_last(); |
| 38 | + $safeResult = \apache_getenv($variable, $walk_to_top); |
| 39 | + if ($safeResult === false) { |
| 40 | + throw ApacheException::createFromPhpError(); |
| 41 | + } |
| 42 | + return $safeResult; |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +/** |
| 47 | + * This performs a partial request for a URI. It goes just far |
| 48 | + * enough to obtain all the important information about the given |
| 49 | + * resource. |
| 50 | + * |
| 51 | + * @param string $filename The filename (URI) that's being requested. |
| 52 | + * @return object An object of related URI information. The properties of |
| 53 | + * this object are: |
| 54 | + * |
| 55 | + * |
| 56 | + * status |
| 57 | + * the_request |
| 58 | + * status_line |
| 59 | + * method |
| 60 | + * content_type |
| 61 | + * handler |
| 62 | + * uri |
| 63 | + * filename |
| 64 | + * path_info |
| 65 | + * args |
| 66 | + * boundary |
| 67 | + * no_cache |
| 68 | + * no_local_copy |
| 69 | + * allowed |
| 70 | + * send_bodyct |
| 71 | + * bytes_sent |
| 72 | + * byterange |
| 73 | + * clength |
| 74 | + * unparsed_uri |
| 75 | + * mtime |
| 76 | + * request_time |
| 77 | + * |
| 78 | + * |
| 79 | + * Returns FALSE on failure. |
| 80 | + * @throws ApacheException |
| 81 | + * |
| 82 | + */ |
| 83 | +function apache_lookup_uri(string $filename): object |
| 84 | +{ |
| 85 | + error_clear_last(); |
| 86 | + $safeResult = \apache_lookup_uri($filename); |
| 87 | + if ($safeResult === false) { |
| 88 | + throw ApacheException::createFromPhpError(); |
| 89 | + } |
| 90 | + return $safeResult; |
| 91 | +} |
| 92 | + |
| 93 | + |
| 94 | +/** |
| 95 | + * Fetches all HTTP request headers from the current request. Works in the |
| 96 | + * Apache, FastCGI, CLI, and FPM webservers. |
| 97 | + * |
| 98 | + * @return array An associative array of all the HTTP headers in the current request. |
| 99 | + * @throws ApacheException |
| 100 | + * |
| 101 | + */ |
| 102 | +function apache_request_headers(): array |
| 103 | +{ |
| 104 | + error_clear_last(); |
| 105 | + $safeResult = \apache_request_headers(); |
| 106 | + if ($safeResult === false) { |
| 107 | + throw ApacheException::createFromPhpError(); |
| 108 | + } |
| 109 | + return $safeResult; |
| 110 | +} |
| 111 | + |
| 112 | + |
| 113 | +/** |
| 114 | + * Fetch all HTTP response headers. Works in the |
| 115 | + * Apache, FastCGI, CLI, and FPM webservers. |
| 116 | + * |
| 117 | + * @return array An array of all Apache response headers on success. |
| 118 | + * @throws ApacheException |
| 119 | + * |
| 120 | + */ |
| 121 | +function apache_response_headers(): array |
| 122 | +{ |
| 123 | + error_clear_last(); |
| 124 | + $safeResult = \apache_response_headers(); |
| 125 | + if ($safeResult === false) { |
| 126 | + throw ApacheException::createFromPhpError(); |
| 127 | + } |
| 128 | + return $safeResult; |
| 129 | +} |
| 130 | + |
| 131 | + |
| 132 | +/** |
| 133 | + * apache_setenv sets the value of the Apache |
| 134 | + * environment variable specified by |
| 135 | + * variable. |
| 136 | + * |
| 137 | + * @param string $variable The environment variable that's being set. |
| 138 | + * @param string $value The new variable value. |
| 139 | + * @param bool $walk_to_top Whether to set the top-level variable available to all Apache layers. |
| 140 | + * @throws ApacheException |
| 141 | + * |
| 142 | + */ |
| 143 | +function apache_setenv(string $variable, string $value, bool $walk_to_top = false): void |
| 144 | +{ |
| 145 | + error_clear_last(); |
| 146 | + $safeResult = \apache_setenv($variable, $value, $walk_to_top); |
| 147 | + if ($safeResult === false) { |
| 148 | + throw ApacheException::createFromPhpError(); |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | + |
| 153 | +/** |
| 154 | + * Fetches all HTTP headers from the current request. |
| 155 | + * |
| 156 | + * This function is an alias for apache_request_headers. |
| 157 | + * Please read the apache_request_headers |
| 158 | + * documentation for more information on how this function works. |
| 159 | + * |
| 160 | + * @return array An associative array of all the HTTP headers in the current request. |
| 161 | + * @throws ApacheException |
| 162 | + * |
| 163 | + */ |
| 164 | +function getallheaders(): array |
| 165 | +{ |
| 166 | + error_clear_last(); |
| 167 | + $safeResult = \getallheaders(); |
| 168 | + if ($safeResult === false) { |
| 169 | + throw ApacheException::createFromPhpError(); |
| 170 | + } |
| 171 | + return $safeResult; |
| 172 | +} |
| 173 | + |
| 174 | + |
| 175 | +/** |
| 176 | + * virtual is an Apache-specific function which |
| 177 | + * is similar to <!--#include virtual...--> in |
| 178 | + * mod_include. |
| 179 | + * It performs an Apache sub-request. It is useful for including |
| 180 | + * CGI scripts or .shtml files, or anything else that you would |
| 181 | + * parse through Apache. Note that for a CGI script, the script |
| 182 | + * must generate valid CGI headers. At the minimum that means it |
| 183 | + * must generate a Content-Type header. |
| 184 | + * |
| 185 | + * To run the sub-request, all buffers are terminated and flushed to the |
| 186 | + * browser, pending headers are sent too. |
| 187 | + * |
| 188 | + * @param string $uri The file that the virtual command will be performed on. |
| 189 | + * @throws ApacheException |
| 190 | + * |
| 191 | + */ |
| 192 | +function virtual(string $uri): void |
| 193 | +{ |
| 194 | + error_clear_last(); |
| 195 | + $safeResult = \virtual($uri); |
| 196 | + if ($safeResult === false) { |
| 197 | + throw ApacheException::createFromPhpError(); |
| 198 | + } |
| 199 | +} |
0 commit comments