From b87ffe00b00d9d473db15ebd251553b17a5eff94 Mon Sep 17 00:00:00 2001
From: filippo.bertilotti <filippobertilotti@gmail.com>
Date: Mon, 20 May 2024 09:46:24 +0200
Subject: [PATCH] inizializzazione .env e classe apposita che la gestisce (parte 110)

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

diff --git a/index.php b/index.php
index 9fc5c34..d97f727 100644
--- a/index.php
+++ b/index.php
@@ -1,32 +1,32 @@
 <?php
 
+declare(strict_types= 1);
+
 spl_autoload_register(function ($class) {
     require "src/". str_replace("\\", "/", $class). ".php";
  });
 
+$dotenv = new Framework\Dotenv;
+$dotenv->load(".env");
+print_r($_ENV);
+
+set_error_handler("Framework\ErrorHandler::handleError");
+
+set_exception_handler("Framework\ErrorHandler::handleException");
+
+
 $path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
-$segments = explode("/", $path);
-
-$router = new Framework\Router;
-
-//$router->add("/{controller}/{action}");
-$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"]);
-
-
-$params = $router->match($path);
-
-if($params === false) {
-    exit("No routes matched");
+if ($path === false) {
+    throw new UnexpectedValueException("Malformed URL: {$_SERVER["REQUEST_URI"]}");
 }
 
-$controller = "App\Controllers\\" . ucwords($params["controller"]);
-$action = $params["action"];
+$segments = explode("/", $path);
 
-$controller_object = new $controller;
+$router = require "config/routes.php";
 
-$controller_object->$action();
+$container = require "config/services.php";
+
+$dispatcher = new Framework\Dispatcher($router, $container);
+
+$dispatcher->handle($path);
     
\ No newline at end of file

--
Gitblit v1.8.0