From addab242fe3986ab8e76aaa4448609ffbf9616ab Mon Sep 17 00:00:00 2001 From: filippo.bertilotti <filippobertilotti@gmail.com> Date: Thu, 16 May 2024 10:30:04 +0200 Subject: [PATCH] aggiunta possibilità di vedere gli errori o no (parte 98) --- index.php | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 43 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index cde5a61..2227691 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,45 @@ <?php -require "controller.php"; -$controller = new Controller; -$controller->index(); \ No newline at end of file +declare(strict_types= 1); +$show_errors = true; + +if($show_errors) { + ini_set("display_errors", "1"); +}else{ + ini_set("display_errors","0"); +} + + +spl_autoload_register(function ($class) { + require "src/". str_replace("\\", "/", $class). ".php"; + }); + +$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}"); + +$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); + \ No newline at end of file -- Gitblit v1.8.0