-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
48 lines (35 loc) · 746 Bytes
/
index.php
File metadata and controls
48 lines (35 loc) · 746 Bytes
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
43
44
45
46
47
48
<?php
require_once __DIR__ . "/controller/TestController.php";
function getArgumentStart($uri)
{
foreach($uri as $key => $value)
{
if($value === 'index.php')
{
if($key === count($uri) - 1)
{
return -1;
}
return $key + 1;
}
}
}
$uri = parse_url($_SERVER['REQUEST_URI']);
$params = explode("/", $uri['path']);
$start = getArgumentStart($params);
if($start !== -1)
{
$controllerName = $params[$start];
$functionName = $params[$start + 1] . ucfirst(strtolower($_SERVER['REQUEST_METHOD']));
$args = [];
$start += 2;
for(; $start < count($params); $start++)
{
array_push($args, $params[$start]);
}
call_user_func_array([new $controllerName, $functionName], $args);
}
else
{
echo "404 page not found";
}