aboutsummaryrefslogtreecommitdiff
path: root/app/class/routes.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/class/routes.php')
-rw-r--r--app/class/routes.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/class/routes.php b/app/class/routes.php
new file mode 100644
index 0000000..6f37b93
--- /dev/null
+++ b/app/class/routes.php
@@ -0,0 +1,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');
+ }
+ }
+} \ No newline at end of file