<?php

namespace App\Core;

use App\Helpers\Logger;

class App
{
    private Router $router;
    private string $basePath;

    public function __construct(string $basePath)
    {
        $this->basePath = $basePath;
        $this->router = new Router();
    }

    public function run(): void
    {
        Config::load($this->basePath);

        session_start();

        View::setBasePath($this->basePath);
        Logger::setBasePath($this->basePath);

        $this->loadRoutes();

        $method = $_SERVER['REQUEST_METHOD'];
        $uri = $_SERVER['REQUEST_URI'];

        $this->router->dispatch($method, $uri);
    }

    private function loadRoutes(): void
    {
        $router = $this->router;
        require $this->basePath . '/config/routes.php';
    }
}
