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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
<?php
class Backrouter
{
protected $route;
protected $altorouter;
const ROUTES = [
'art' => ['art', 'read'],
'art aff=read' => ['art', 'read'],
'art aff=edit' => ['art', 'edit'],
'art aff=log' => ['art', 'log'],
'art action=update' => ['art', 'update'],
'art action=update home' => ['art', 'update', 'home'],
'art action=add' => ['art', 'add'],
'art action=delete' => ['art', 'delete'],
'aff=home action=massedit',
'aff=home' => ['home', 'desktop'],
'' => ['home', 'desktop'],
'aff=home action=massedit' => ['home', 'massedit'],
'action=massedit' => ['home', 'massedit'],
'action=analyseall' => ['home', 'analyseall'],
'aff=home action=analyseall' => ['home', 'analyseall'],
'art action=login' => ['art', 'login', 'art'],
'home action=login' => ['home', 'login', 'home'],
'action=login' => ['home', 'login'],
'art action=logout' => ['art', 'logout', 'art'],
'home action=logout' => ['home', 'logout', 'home'],
'action=logout' => ['home', 'logout'],
'aff=db' => ['db', 'desktop'],
'aff=db action=add' => ['db', 'add'],
'aff=media' => ['media', 'desktop'],
'aff=media action=addmedia' => ['media', 'addmedia'],
'aff=admin' => ['admin', 'desktop'],
'aff=co' => ['connect', 'desktop'],
];
public function __construct($router)
{
$this->altorouter = $router;
}
public function run() {
if($this->matchroute()) {
$this->callmethod();
} else {
echo '<h1>404 Error</h1>';
}
}
public function matchroute()
{
$this->route = new route($_GET);
$match = array_key_exists($this->route->tostring(), self::ROUTES);
return $match;
}
public function callmethod()
{
$method = self::ROUTES[$this->route->tostring()];
$class = 'controller' . $method[0];
$function = $method[1];
$controller = new $class($this->altorouter);
$params = array_slice($method, 2);
$controller->$function(...$params);
}
}
?>
|