-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
37 lines (29 loc) · 848 Bytes
/
index.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
<?php
// for project url
$base_url = "/route/";
$routes = [];
function route(string $path, callable $callback)
{
global $routes,$base_url;
$end_url = $base_url.$path;
$end_url = explode("/", $end_url);
// menghilangkan array yang kosong
$end_url = array_filter($end_url, function($value) { return !is_null($value) && $value !== ''; });
$end_url = "/".implode("/", $end_url);
if($path == "/"){
$end_url .= "/";
}
$routes[$end_url] = $callback;
}
function execute()
{
global $routes;
$uri = $_SERVER['REQUEST_URI'];
foreach ($routes as $path => $callback) {
if($path != $uri) continue;
$callback();
}
}
include 'routes/web.php';
execute();
?>