<?php
declare(strict_types=1);
$request=json_decode(file_get_contents(__DIR__.'/private/request.json'),true);$path=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);$case=null;foreach($request['cases']as $c)if($c['label']===($_SERVER['HTTP_X_CDX_CASE']??'')&&$c['path']===$path)$case=$c;
if(!$case||$_SERVER['REQUEST_METHOD']!=='POST'||($_SERVER['HTTP_TOKEN']??'')!==$request['token']){http_response_code(403);exit;}$actual=$_POST;$expected=$case['params'];ksort($actual);ksort($expected);if($actual!==$expected){http_response_code(403);exit;}
$phase=$_SERVER['HTTP_X_CDX_PHASE']??'original';if(!in_array($phase,['original','retest','final'],true)||($phase==='retest'&&(!in_array($case['label'],['list-positive','list-page2','list-status40','detail-positive'],true)||getenv('FL_LANE')!=='B'))||($phase==='final'&&!in_array($case['label'],['list-positive','detail-positive'],true))){http_response_code(403);exit;}$wireName='wire-'.$case['label'].($phase!=='original'?'-'.$phase:'').'.json';if(is_file(__DIR__.'/private/'.$wireName)){http_response_code(409);exit;}
foreach(json_decode(file_get_contents(__DIR__.'/source-lock.json'),true)as $file=>$sha)if(hash_file('sha256',__DIR__.'/source/application/'.$file)!==$sha){http_response_code(409);exit;}
require __DIR__.'/common.php';$before=$source();$base=json_decode(file_get_contents(__DIR__.'/private/batch-before.json'),true);foreach($before as $k=>$v)if($v!==$base[$k])throw new RuntimeException('Request source drift '.$k);
require __DIR__.'/NativeGate.php';FLGate::$deny=$case['kind']==='unreachable';$GLOBALS['FL_ORACLE']=[];$started=microtime(true);ob_start();
register_shutdown_function(static function()use($source,$before,$case,$save,$started,$wireName){$body=(string)ob_get_contents();$after=$source();$reflection=[];foreach(['app\\p\\controller\\SupplementMealOrder','app\\p\\logic\\SupplementMealOrder','app\\cores\\database\\Dm','think\\db\\connector\\Mysql']as $class)if(class_exists($class,false)){$file=(new ReflectionClass($class))->getFileName();$reflection[$class]=['file'=>$file,'sha256'=>hash_file('sha256',$file)];}$r=['label'=>$case['label'],'path'=>$case['path'],'params'=>$case['params'],'kind'=>$case['kind'],'status'=>http_response_code(),'body'=>$body,'body_sha256'=>hash('sha256',$body),'source_lock_sha256'=>hash_file('sha256',__DIR__.'/source-lock.json'),'reflection'=>$reflection,'source_before'=>$before,'source_after'=>$after,'native'=>FLGate::$journal,'oracle'=>$GLOBALS['FL_ORACLE'],'source_unchanged'=>$before===$after,'duration'=>microtime(true)-$started,'last_error'=>error_get_last()];$save($wireName,$r);});
$_SERVER['PATH_INFO']=$path;require __DIR__.'/app-init.php';\think\App::run()->send();
