<?php
namespace Core\System;

class Request {

    public static function method()
    {
        return $_SERVER['REQUEST_METHOD'] ?? 'GET';
    }

    public static function uri()
    {
        $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        $uri = trim($uri, '/');

        $folder = basename(dirname(__DIR__, 3)); 
        $folderLower = strtolower($folder);
        $uriLower = strtolower($uri);

        if ($uriLower === $folderLower) {
            return '';
        }

        if (strpos($uriLower, $folderLower . '/') === 0) {
            $uri = substr($uri, strlen($folder) + 1);
        }

        return trim($uri, '/');
    }

    public static function input($key = null)
    {
        $data = array_merge($_GET, $_POST);
        return $key ? ($data[$key] ?? null) : $data;
    }
}
