<?php
namespace think;

// 优先使用 public 目录内的 vendor 符号链接（如果存在）
$autoloadFile = __DIR__ . '/vendor/autoload.php';

// 如果符号链接不存在，尝试使用上级目录的 vendor
if (!file_exists($autoloadFile)) {
    $rootPath = dirname(__DIR__);
    $autoloadFile = $rootPath . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
    
    // 尝试临时修改 open_basedir（如果允许）
    $basedir = ini_get('open_basedir');
    if ($basedir && !file_exists($autoloadFile)) {
        $basedirPaths = explode(PATH_SEPARATOR, $basedir);
        if (!in_array($rootPath, $basedirPaths)) {
            @ini_set('open_basedir', $basedir . PATH_SEPARATOR . $rootPath);
        }
    }
}

if (file_exists($autoloadFile)) {
    require $autoloadFile;
} else {
    die('Vendor autoload file not found. Please run: composer install or create a symlink: ln -s ../vendor public/vendor');
}

$http = (new App())->http;

$response = $http->run();

$response->send();

$http->end($response);
