<?php
$case=json_decode((string)file_get_contents(__DIR__.'/private/current.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');if(!$case||!preg_match('/^F0[1-8]$/D',$case['label'])||$path!==$case['path']||($_SERVER['HTTP_TOKEN']??'')!==$auth['token']||($_SERVER['HTTP_X_CDX_CASE']??'')!==$case['label']||json_decode($raw,true)!==$case['params']||$_SERVER['REQUEST_METHOD']!=='POST'||file_exists(__DIR__.'/private/wire-'.$case['label'].'.json')){http_response_code(403);exit;}
require __DIR__.'/common.php';$before=$source($case['own_id']??null);$lease=json_decode(file_get_contents(__DIR__.'/private/lease.json'),true);if($before!==$lease)throw new RuntimeException('Independent fresh own62/category lease');require __DIR__.'/Gate.php';FoodGate::$case=$case;$record=['case'=>$case,'raw_request_base64'=>base64_encode($raw),'before'=>$before];$warnings=[];$old=null;$old=set_error_handler(static function($s,$m,$f,$l)use(&$warnings,&$old){$warnings[]=['severity'=>$s,'message'=>$m,'file'=>$f,'line'=>$l];return is_callable($old)?call_user_func($old,$s,$m,$f,$l):false;});ob_start();
try{$_SERVER['PATH_INFO']=$path;require __DIR__.'/init.php';$response=\think\App::run();$save('response-'.$case['label'].'.json',['status'=>$response->getCode(),'headers'=>$response->getHeader(),'body'=>$response->getContent(),'body_sha256'=>hash('sha256',$response->getContent())]);$save('execution-'.$case['label'].'.json',['native'=>FoodGate::$journal,'DML_attempts'=>FoodGate::$dml,'warnings'=>$warnings]);$response->send();}catch(Throwable $e){$record['business_error']=['class'=>get_class($e),'message'=>$e->getMessage()];}
$record['body']=(string)ob_get_contents();$record['status']=http_response_code();$record['headers']=headers_list();ob_end_flush();flush();$record['native']=FoodGate::$journal;$record['DML_attempts']=FoodGate::$dml;$record['warnings']=$warnings;$record['included_files']=[];foreach(get_included_files()as $f)$record['included_files'][]=['path'=>$f,'sha256'=>hash_file('sha256',$f)];$record['transport_spy']=$GLOBALS['FOOD_TRANSPORT_SPY']??[];$record['notification_spy']=$GLOBALS['FOOD_NOTIFICATION_SPY']??[];$record['tchef_config_isolation_calls']=$GLOBALS['FOOD_TCHEF_CONFIG_ISOLATION_CALLS']??[];
try{$id=$case['own_id']??FoodGate::$generatedId;$record['after']=$source($id);$guard($before,$record['after']);$record['protected_equal']=true;$record['observer']=$GLOBALS['FOOD_OBSERVER'];}catch(Throwable $e){$record['observer_error']=['class'=>get_class($e),'message'=>$e->getMessage()];$record['observer']=$GLOBALS['FOOD_OBSERVER'];}restore_error_handler();$save('wire-'.$case['label'].'.json',$record);
