| Total Complexity | 6 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 3 | class http_lib extends Library { |
||
| 4 | function response_code($code, $view_and_exit = true, $view_name = false) { |
||
|
|
|||
| 5 | http_response_code($code); |
||
| 6 | if ($view_and_exit) { |
||
| 7 | if (empty($view_name)) { |
||
| 8 | $view_name = strval($code); |
||
| 9 | } |
||
| 10 | // Check if a dedicated view exists; if not, load common error view |
||
| 11 | $dedicated_view = $this->load_view($view_name, [ |
||
| 12 | 'error_code' => $code, |
||
| 13 | ]); |
||
| 14 | if (! $dedicated_view) { |
||
| 15 | $this->load_view('http_error', [ |
||
| 16 | 'error_code' => $code, |
||
| 17 | ]); |
||
| 18 | } |
||
| 19 | exit(); |
||
| 20 | } |
||
| 21 | } |
||
| 22 | |||
| 23 | function redirect($url, $status_code = 302) { |
||
| 24 | header('Location: ' . $url, true, $status_code); |
||
| 25 | exit(); |
||
| 26 | } |
||
| 27 | |||
| 28 | function canonical_of($url) { |
||
| 30 | } |
||
| 31 | |||
| 32 | } |
||
| 33 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.