| | |
| | | <?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); |
| | | |
| | | $controller = $segments[1]; |
| | | $action = $segments[2]; |
| | | $router = require "config/routes.php"; |
| | | |
| | | require "src/controllers/$controller.php"; |
| | | $container = new Framework\Container; |
| | | |
| | | $controller_object = new $controller; |
| | | |
| | | $controller_object->$action(); |
| | | $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); |
| | | |