-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouting.php
More file actions
35 lines (28 loc) · 1.03 KB
/
Routing.php
File metadata and controls
35 lines (28 loc) · 1.03 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
<?
require_once 'src/controllers/DefaultController.php';
require_once 'src/controllers/SecurityController.php';
require_once 'src/controllers/EditProfileController.php';
require_once 'src/controllers/AnnouncementController.php';
require_once 'src/controllers/ProfileController.php';
require_once 'src/controllers/NotificationController.php';
require_once 'src/controllers/RatingController.php';
class Routing{
public static array $routes;
public static function get($url, $controller){
self::$routes[$url] = $controller;
}
public static function post($url, $controller){
self::$routes[$url] = $controller;
}
public static function run($url){
$urlParts = explode("/", $url);
$action = $urlParts[0];
if(!array_key_exists($action, self::$routes)){
die("Wrong url");
}
$controller = self::$routes[$action];
$object = new $controller;
$id = $urlParts[1] ?? '';
$action == "" ? $object->index() : $object->$action($id);
}
}