<?php

namespace App\Http\Controllers;

use App\Support\LegacyPhp;
use Illuminate\Http\Response;

class LegacyApiController extends Controller
{
    public function run(string $script): Response
    {
        $script = str_replace('\\', '/', $script);
        $path = base_path('resources/legacy/api/v1/'.$script);

        if (! is_file($path) && ! str_ends_with($script, '.php')) {
            $script .= '.php';
        }

        return LegacyPhp::render('resources/legacy/api/v1/'.$script);
    }
}
