-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.php
More file actions
47 lines (35 loc) · 1.06 KB
/
handler.php
File metadata and controls
47 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
class Handler {
public $template = null;
public function load($path, array $args = array()){
return $this->template->load($path, $args);
}
public function render($path, array $args = array()){
return $this->template->render($path, $args);
}
public function isAjax(){
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';
}
public function write($content, $type = 'text/html', $status_code = 200){
header('Content-type: '. $type);
http_response_code($status_code);
echo $content;
}
public function json(array $data = array(), $status_code = 200){
return $this->write(json_encode($data), 'application/json', $status_code);
}
public function redirect($path){
header('Location: '. $path);
die();
}
}
class FourOhFour extends Handler {
public function get(){
echo 'not found, fam. 404';
}
}
class FiveOhOh extends Handler {
public function get(){
echo '500!';
}
}