<?php
namespace Root\Core\Helper;

class UrlHelper
{
    public static function addQuery(string $url, array $params): string
    {
        $parsed = parse_url($url);
        $query = isset($parsed['query']) ? parse_str($parsed['query'], $existing) ? $existing : [] : [];
        $merged = http_build_query(array_merge($query ?? [], $params));
        return "{$parsed['scheme']}://{$parsed['host']}{$parsed['path']}?$merged";
    }

    public static function isSecure(): bool
    {
        return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443;
    }
}
