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
|
<?php
class Routes
{
/**
* Cherche une correspondance entre l'URL et les routes, et appelle la méthode appropriée
*/
public function match()
{
$router = new AltoRouter();
$router->addRoutes([
['GET|POST', '/', 'Backrouter#run', 'backrouter'],
['GET', '/[a:art]/', 'Controllerart#read', 'artread/'],
['GET', '/[a:art]', 'Controllerart#read', 'artread'],
['GET', '/[a:art]/edit', 'Controllerart#edit', 'artedit'],
['GET', '/[a:art]/edit/', 'Controllerart#edit', 'artedit/'],
]);
$match = $router->match();
if ($match) {
$callableParts = explode('#', $match['target']);
$controllerName = $callableParts[0];
$methodName = $callableParts[1];
$controller = new $controllerName();
call_user_func_array(array($controller, $methodName), $match['params']);
}
//404
else {
header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}
}
}
|