<?php
$root=getenv('PM_ROOT');$path=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);if($_SERVER['REQUEST_METHOD']!=='POST'||!in_array($path,['/p/trainunit/lists','/p/trainunit/info','/p/trainunit/allunit','/p/trainannex/lists'],true)){http_response_code(403);exit;}
foreach(json_decode(file_get_contents(__DIR__.'/private-lock.json'),true)as $f=>$sha)if(hash_file('sha256',__DIR__.'/source/application/'.$f)!==$sha){http_response_code(403);exit;}
foreach(['p/controller','p/logic','model','validate']as $dir)if(is_file(__DIR__.'/source/application/'.$dir.'/TrainUnit.php')){http_response_code(403);exit;}
$baseline=json_decode(file_get_contents(__DIR__.'/private-baseline.json'),true);if($path==='/p/trainannex/lists'&&((isset($_POST['type'])&&(string)$_POST['type']!=='1')||(isset($_POST['uuid'])&&!in_array($_POST['uuid'],[$baseline['scope'],$baseline['empty']],true)))){http_response_code(403);exit;}
ob_start();register_shutdown_function(static function()use($path):void{file_put_contents(__DIR__.'/private-wire.jsonl',json_encode(['label'=>$_SERVER['HTTP_X_CDX_CASE']??'','method'=>'POST','path'=>$path,'http_status'=>http_response_code(),'response'=>(string)ob_get_contents()],JSON_UNESCAPED_UNICODE)."\n",FILE_APPEND);chmod(__DIR__.'/private-wire.jsonl',0600);});
$_SERVER['PATH_INFO']=$path;require $root.'/env.php';if(!function_exists('json')){function json($data=[],$code=200,array $header=[],$options=[]){return \think\Response::create($data,'json',$code,$header,$options);}}
require $root.'/external_stubs.php';define('APP_PATH',__DIR__.'/source/application/');define('RUNTIME_PATH',__DIR__.'/runtime/');require $root.'/thinkphp/base.php';\think\App::initCommon();\think\Log::init(['type'=>'File','path'=>__DIR__.'/runtime/safe-log/','level'=>['no_raw_application_log']]);\think\Config::set(['type'=>'File','path'=>__DIR__.'/cache/','prefix'=>'TRAINREAD10_'],'cache');\think\Config::set('redis',[]);$database=require $root.'/application/database.php';\think\Config::set($database,'database');\think\Db::clear();\think\App::run()->send();
