aboutsummaryrefslogtreecommitdiff
path: root/app/class/routes.php
blob: f24492b242bb5a415a8e20903154b8b6e04ec14c (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
<?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->setBasePath(Config::basepath());
        $router->addRoutes([
            ['GET|POST', '/', 'Backrouter#run', 'backrouter'],
            ['GET', '/[a:art]/', 'Controllerart#read', 'artread/'],
            ['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($router);
			
            call_user_func_array(array($controller, $methodName), $match['params']);
        }
		//404
        else {
            header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
        }
    }
}