<?php
$path=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);$request=json_decode(file_get_contents(__DIR__.'/private-request.json'),true);$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;}$a=$_POST;$b=$case['params'];ksort($a);ksort($b);if($a!==$b){http_response_code(403);exit;}foreach(json_decode(file_get_contents(__DIR__.'/private-source-lock.json'),true) as $file=>$sha)if(hash_file('sha256',__DIR__.'/source/application/'.$file)!==$sha){http_response_code(403);exit;}
require __DIR__.'/common.php';$before=$source();$guard($before);$GLOBALS['CDX_PREPARED']=[];$GLOBALS['NUTRITION_MEDIA_CALLS']=0;$started=microtime(true);ob_start();register_shutdown_function(static function()use($source,$guard,$before,$case,$started){try{$body=(string)ob_get_contents();$after=$source();$guard($after);$reflection=[];foreach(['app\\p\\logic\\NutritionTemplate','app\\p\\logic\\NutritionStation','app\\p\\logic\\Nutrition','app\\m\\logic\\Nutrition','app\\model\\NutritionTemplate','app\\model\\NutritionSet'] as $class)if(class_exists($class,false)){$file=(new ReflectionClass($class))->getFileName();$reflection[$class]=['file'=>$file,'sha256'=>hash_file('sha256',$file)];}$headers=[];foreach(headers_list() as $h)if(preg_match('/^(Content-Type|X-Powered-By):/i',$h))$headers[]=$h;$record=['label'=>$case['label'],'path'=>$case['path'],'params'=>$case['params'],'status'=>http_response_code(),'headers'=>$headers,'body'=>$body,'body_sha256'=>hash('sha256',$body),'source_before'=>$before,'source_after'=>$after,'oracle_native_SELECT'=>$GLOBALS['ORACLE_JOURNAL'],'prepared_SQL'=>$GLOBALS['CDX_PREPARED'],'reflection'=>$reflection,'media_leaf_calls'=>$GLOBALS['NUTRITION_MEDIA_CALLS'],'duration_seconds'=>microtime(true)-$started,'error'=>error_get_last()];file_put_contents(__DIR__.'/private-retest-wire.jsonl',json_encode($record,JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION)."\n",FILE_APPEND);chmod(__DIR__.'/private-retest-wire.jsonl',0600);}catch(Throwable $e){file_put_contents(__DIR__.'/private-audit-error',get_class($e).':'.$e->getMessage());chmod(__DIR__.'/private-audit-error',0600);}});
$_SERVER['PATH_INFO']=$path;require __DIR__.'/media-leaf.php';require __DIR__.'/init.php';\think\App::run()->send();
