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 | 60 +++++++++++------------------------------------------------- 1 files changed, 11 insertions(+), 49 deletions(-) diff --git a/index.php b/index.php index d1e2763..d97f727 100644 --- a/index.php +++ b/index.php @@ -2,42 +2,18 @@ declare(strict_types= 1); -set_error_handler(function( - int $errno, - string $errstr, - string $errfile, - int $errline - ): bool - { - throw new ErrorException($errstr,0, $errno, $errfile, $errline); -}); - - -set_exception_handler(function (Throwable $exception) { - static $show_errors = false; - - if($exception instanceof Framework\Exceptions\PageNotFoundException) { - http_response_code(404); - $template = "404.php"; - } else { - http_response_code(500); - $template = "500.php"; - } - - if($show_errors) { - ini_set("display_errors", "1"); - }else{ - ini_set("display_errors","0"); - ini_set("log_errors","1"); - require "views/$template"; - } - - throw $exception; -}); - 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); if ($path === false) { @@ -46,23 +22,9 @@ $segments = explode("/", $path); -$router = new Framework\Router; +$router = require "config/routes.php"; -$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"); -}); +$container = require "config/services.php"; $dispatcher = new Framework\Dispatcher($router, $container); -- Gitblit v1.8.0