blob: c8f51e3eb78ca15000157948f3c89624769c997b (
plain)
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
|
<?php
class Router
{
protected $routes = [
'GET' => [],
'POST' => [],
'HEAD' => []
];
public function get($uri, $controller)
{
$this->routes['GET'][$uri] = $controller;
}
public function post($uri, $controller)
{
$this->routes['POST'][$uri] = $controller;
}
public function head($uri, $controller)
{
$this->routes['HEAD'][$uri] = $controller;
}
public static function load($file)
{
$router = new static;
require $file;
return $router;
}
public function direct($uri, $requestType)
{
if (is_array($this->routes[$requestType]) && array_key_exists($uri, $this->routes[$requestType])) {
return $this->routes[$requestType][$uri];
}
die(http_response_code(404));
}
}
|