From f6df29226eaad3c37245b8774de6639acf589b1d Mon Sep 17 00:00:00 2001
From: filippo.bertilotti <filippobertilotti@gmail.com>
Date: Fri, 10 May 2024 11:23:50 +0200
Subject: [PATCH] refactor code index dispatcher (parte 64)

---
 index.php |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/index.php b/index.php
index 6d5a3fb..9ebc44a 100644
--- a/index.php
+++ b/index.php
@@ -1,7 +1,22 @@
 <?php
-    require "model.php";
-    
-    $model = new Model;
-    $products = $model->getData();
 
-    require "view.php";
\ No newline at end of file
+spl_autoload_register(function ($class) {
+    require "src/". str_replace("\\", "/", $class). ".php";
+ });
+
+$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
+$segments = explode("/", $path);
+
+$router = new Framework\Router;
+
+$router->add("/product/{slug:[\w-]+}", ["controller" => "products", "action" => "show"]);
+$router->add("/{controller}/{id:\d+}/{action}");
+$router->add("/home/index", ["controller" => "home", "action" => "index"]);
+$router->add("/products", ["controller" => "products", "action" => "index"]);
+$router->add("/", ["controller" => "home", "action" => "index"]);
+$router->add("/{controller}/{action}");
+
+$dispatcher = new Framework\Dispatcher($router);
+
+$dispatcher->handle($path);
+    
\ No newline at end of file

--
Gitblit v1.8.0