corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-24 e99f0be8d819e5c71bfcdd0ccdf3c4d3758dd62d
commit | author | age
c4c562 1 <?php
7301d1 2
9e69c2 3 declare(strict_types= 1);
eab392 4
ab9633 5 define ("ROOT_PATH", dirname(__DIR__));
2ab29e 6 spl_autoload_register(function ($class) {
ab9633 7     require ROOT_PATH . "/src/". str_replace("\\", "/", $class). ".php";
2ab29e 8  });
F 9
b87ffe 10 $dotenv = new Framework\Dotenv;
ab9633 11 $dotenv->load(ROOT_PATH . "/.env");
b87ffe 12
2ab29e 13 set_error_handler("Framework\ErrorHandler::handleError");
eab392 14
4ee40e 15 set_exception_handler("Framework\ErrorHandler::handleException");
9e69c2 16
0c028b 17
001175 18 $path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
9e69c2 19 if ($path === false) {
F 20     throw new UnexpectedValueException("Malformed URL: {$_SERVER["REQUEST_URI"]}");
21 }
22
001175 23 $segments = explode("/", $path);
F 24
ab9633 25 $router = require ROOT_PATH . "/config/routes.php";
4ce2a5 26
ab9633 27 $container = require ROOT_PATH . "/config/services.php";
95ec24 28
2bddb6 29 $dispatcher = new Framework\Dispatcher($router, $container);
f6df29 30
F 31 $dispatcher->handle($path);
7bc6e3 32