<?php

declare(strict_types=1);

namespace App\Core\Routing;

use App\Shared\Support\Path;

final class RedirectAction
{
    public function __construct(private readonly string $to)
    {
    }

    public function __invoke(): void
    {
        $target = $this->to;
        if (preg_match('#^https?://#i', $target) !== 1) {
            $target = Path::url($target);
        }

        header('Location: ' . $target);
        exit;
    }
}
