From 3c7c8c2cce7a5153546d30aa0c39372d1e45690e Mon Sep 17 00:00:00 2001
From: filippo.bertilotti <filippobertilotti@gmail.com>
Date: Fri, 17 May 2024 11:50:57 +0200
Subject: [PATCH] creazione file config apposito per le routes (parte 107)

---
 index.php |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/index.php b/index.php
index b6fbdfa..0a93231 100644
--- a/index.php
+++ b/index.php
@@ -1,25 +1,32 @@
 <?php
 
+declare(strict_types= 1);
+
 spl_autoload_register(function ($class) {
     require "src/". str_replace("\\", "/", $class). ".php";
  });
 
+set_error_handler("Framework\ErrorHandler::handleError");
+
+set_exception_handler("Framework\ErrorHandler::handleException");
+
+
 $path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
+if ($path === false) {
+    throw new UnexpectedValueException("Malformed URL: {$_SERVER["REQUEST_URI"]}");
+}
+
 $segments = explode("/", $path);
 
-$router = new Framework\Router;
-
-$router->add("/admin/{controller}/{action}", ["namespace" => "Admin"]);
-$router->add("/product/{slug:[\w-]+}", ["controller" => "products", "action" => "show"]);
-$router->add("/{title}/{id:\d+}/{page:\d+}", ["controller" => "products", "action" => "showPage"]);
-$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}");
+$router = require "config/routes.php";
 
 $container = new Framework\Container;
 
+
+$container->set(App\Database::class, function() {
+    return new App\Database("localhost", "product_db", "product_db_user", "secret");
+});
+
 $dispatcher = new Framework\Dispatcher($router, $container);
 
 $dispatcher->handle($path);

--
Gitblit v1.8.0