-
Notifications
You must be signed in to change notification settings - Fork 0
/
Routing.php
41 lines (32 loc) · 968 Bytes
/
Routing.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
<?php
require_once 'src/controllers/DefaultController.php';
require_once 'src/controllers/SecurityController.php';
require_once 'src/controllers/EntryController.php';
require_once 'src/controllers/ChallengeController.php';
require_once 'src/controllers/UserController.php';
require_once 'src/controllers/AdminController.php';
class Router
{
public static $routes;
public static function get($url, $view)
{
self::$routes[$url] = $view;
}
public static function post($url, $view)
{
self::$routes[$url] = $view;
}
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;
$action = $action ?: 'index';
$id = $urlParts[1] ?? '';
$object->$action($id);
}
}