<?php
declare(strict_types=1);
$case=json_decode((string)file_get_contents(__DIR__.'/private/current-case.json'),true);$auth=json_decode((string)file_get_contents(__DIR__.'/private/auth.json'),true);$path=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);$raw=file_get_contents('php://input');$actual=strpos($_SERVER['CONTENT_TYPE']??'','application/json')===0?json_decode($raw,true):$_POST;
if(!$case||$case['path']!==$path||($_SERVER['HTTP_X_CDX_CASE']??'')!==$case['label']||($_SERVER['HTTP_TOKEN']??'')!==$auth['token']||$_SERVER['REQUEST_METHOD']!=='POST'||$actual!==$case['params']){http_response_code(403);exit;}
$wire='wire-'.$case['phase'].'-'.$case['label'].'.json';if(is_file(__DIR__.'/private/'.$wire)){http_response_code(409);exit;}
foreach(json_decode(file_get_contents(__DIR__.'/source-lock.json'),true)as $f=>$sha)if(hash_file('sha256',__DIR__.'/source/application/'.$f)!==$sha){http_response_code(409);exit;}
require __DIR__.'/common.php';require __DIR__.'/NativeGate.php';NFGate::$case=$case;NFGate::$phase=$case['phase'];NFGate::$own=$case['own'];$before=$source();$started=microtime(true);ob_start();
register_shutdown_function(static function()use($source,$before,$case,$save,$started,$wire,$raw){$body=(string)ob_get_contents();$reflection=[];foreach(['app\\p\\controller\\Nutrition','app\\m\\controller\\Nutrition','app\\p\\controller\\NutritionTemplate','app\\p\\logic\\Nutrition','app\\m\\logic\\Nutrition','app\\p\\logic\\NutritionTemplate','app\\common\\service\\NutritionFloat82Write','app\\cores\\database\\Dm','think\\db\\connector\\Mysql']as $class)if(class_exists($class,false)){$f=(new ReflectionClass($class))->getFileName();$reflection[$class]=['file'=>$f,'sha256'=>hash_file('sha256',$f)];}$record=['case'=>$case,'raw_request_base64'=>base64_encode($raw),'status'=>http_response_code(),'body'=>$body,'body_sha256'=>hash('sha256',$body),'native'=>NFGate::$journal,'DML_attempts'=>NFGate::$dml,'before'=>$before,'reflection'=>$reflection,'duration'=>microtime(true)-$started,'last_error'=>error_get_last()];try{$record['after']=$source();$record['oracle']=$GLOBALS['NF_ORACLE'];}catch(Throwable $e){$record['oracle_error']=['class'=>get_class($e),'message'=>$e->getMessage()];}$save($wire,$record);});
$_SERVER['PATH_INFO']=$path;require __DIR__.'/app-init.php';\think\App::run()->send();
