-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.php
47 lines (46 loc) · 1.31 KB
/
router.php
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
include("./Controller/user.controller.php");
include("./Controller/product.controller.php");
preg_match_all("#\/([a-zA-Z]*)\/?([0-9]*)#", $_SERVER['REQUEST_URI'], $match);
$method = $_SERVER["REQUEST_METHOD"];
$id = intval($match[2][0]);
header("Content-Type: application/json");
if ($match[1][0] == "Users") {
switch ($method) {
case "GET":
if ($id != 0) {
echo \Controller\getOneUser($id);
} else {
echo \Controller\getAllUsers();
}
break;
case "POST":
echo \Controller\createUser();
break;
case "PUT":
echo \Controller\updateUser($id);
break;
case "DELETE":
echo \Controller\deleteUser($id);
break;
}
}elseif($match[1][0] == "Products"){
switch ($method) {
case "GET":
if ($id != 0) {
echo \Controller\getOneProduct($id);
} else {
echo \Controller\getAllProducts();
}
break;
case "POST":
echo \Controller\createProduct();
break;
case "PUT":
echo \Controller\updateProduct($id);
break;
case "DELETE":
echo \Controller\deleteProduct($id);
break;
}
}