<?php
declare(strict_types=1);
$r=json_decode(file_get_contents(__DIR__.'/private/request.json'),true);$path=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);$case=null;foreach($r['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']??'')!==$r['token']){http_response_code(403);exit;}$actual=$_POST;$expected=$case['params'];ksort($actual);ksort($expected);if($actual!==$expected){http_response_code(403);exit;}
$wire='wire-'.$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;}
if(($_SERVER['HTTP_ACCEPT']??'')!=='application/json, text/plain, */*'||($_SERVER['HTTP_CACHE_CONTROL']??'')!=='max-age=28880'){http_response_code(403);exit;}
require __DIR__.'/common.php';$before=$source();$base=json_decode(file_get_contents(__DIR__.'/private/batch-before10.json'),true);unset($base['sentinel']);if($before!==$base)throw new RuntimeException('Request own source drift');$logBefore=$logs();
require __DIR__.'/NativeGate.php';$GLOBALS['NR_ORACLE']=[];$started=microtime(true);NRGate::$case=$case;NRGate::$started=$started;foreach($logBefore as $log)NRGate::$priorGuids[$log['uuid']]=true;ob_start();
register_shutdown_function(static function()use($source,$logs,$before,$logBefore,$case,$save,$started,$wire){$body=(string)ob_get_contents();$after=$source();$logAfter=$logs();$new=array_slice($logAfter,count($logBefore));$reflection=[];foreach(['app\\p\\controller\\Ontoanalysis','app\\p\\logic\\Ontoanalysis','app\\p\\logic\\DateMenu','app\\model\\DateMenu','app\\cores\\database\\Dm','think\\db\\connector\\Mysql','think\\db\\builder\\Mysql']as $class)if(class_exists($class,false)){$f=(new ReflectionClass($class))->getFileName();$reflection[$class]=['file'=>$f,'sha256'=>hash_file('sha256',$f)];}$save($wire,['label'=>$case['label'],'path'=>$case['path'],'params'=>$case['params'],'actual_client_headers'=>['Accept'=>$_SERVER['HTTP_ACCEPT'],'Cache-Control'=>$_SERVER['HTTP_CACHE_CONTROL']],'status'=>http_response_code(),'body'=>$body,'body_sha256'=>hash('sha256',$body),'source_before'=>$before,'source_after'=>$after,'source_unchanged'=>$before===$after,'logs_before'=>$logBefore,'logs_after'=>$logAfter,'old_logs_unchanged'=>array_slice($logAfter,0,count($logBefore))===$logBefore,'new_logs'=>$new,'expected_log_rows'=>$case['log_rows'],'exact_log_count'=>count($new)===$case['log_rows'],'parsed_native_log_rows'=>NRGate::$inserted,'native'=>NRGate::$journal,'oracle'=>$GLOBALS['NR_ORACLE'],'reflection'=>$reflection,'included_files'=>get_included_files(),'started_epoch'=>$started,'completed_epoch'=>microtime(true),'last_error'=>error_get_last()]);});
$_SERVER['PATH_INFO']=$path;require __DIR__.'/app-init.php';\think\App::run()->send();
