-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRouting.php
42 lines (30 loc) · 916 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
42
<?php
require_once 'src/controllers/DefaultController.php';
require_once 'src/controllers/SecurityController.php';
require_once 'src/controllers/SeatsController.php';
require_once 'src/controllers/MovieController.php';
require_once 'src/controllers/ScreeningController.php';
class Routing
{
public static $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)
{
$action = explode("/", $url)[0];
if (!array_key_exists($action, self::$routes)) {
die("Wrong url!");
}
// TODO call controller method
$controller = self::$routes[$action];
$object = new $controller;
$action = $action ?: 'index';
$object->$action();
}
}