<?php
$root=getenv('PM_ROOT');$path=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);if(!in_array($path,['/p/syllabusEvaluate/lists','/p/syllabusEvaluate/info'],true)||$_SERVER['REQUEST_METHOD']!=='POST'){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__.'/oracle.php';$post=$_POST;$case=$_SERVER['HTTP_X_CDX_CASE']??'';$spec=json_decode(file_get_contents(__DIR__.'/private-spec.json'),true);$matches=array_values(array_filter($spec,static function($s)use($case){return $s['label']===$case;}));if(count($matches)!==1||$path!=='/p/syllabusEvaluate/'.$matches[0]['method']){http_response_code(403);exit;}$expected=array_map('strval',$matches[0]['params']);ksort($expected);$actual=$post;ksort($actual);if($actual!==$expected){http_response_code(403);exit;}
if(in_array($case,['own_list','own_info'],true))require __DIR__.'/fixture-oracle.php';
$before=$source();$beforeActor=$actorNow();$check($actor===$beforeActor,'Actor drift');$absent=$case==='absent_info'?$q('SELECT COUNT(*) AS CNT FROM '.$p.'syllabus_evaluate WHERE UUID=?',[$post['uuid']])[0]['cnt']:null;
ob_start();register_shutdown_function(static function()use($case,$path,$post,$before,$beforeActor,$source,$actorNow,$absent,$q,$p):void{try{$entry=['label'=>$case,'phase'=>$_SERVER['HTTP_X_CDX_PHASE']??'initial','path'=>$path,'params'=>$post,'status'=>http_response_code(),'response'=>(string)ob_get_contents(),'source_before'=>$before,'source_after'=>$source(),'actor_before'=>$beforeActor,'actor_after'=>$actorNow(),'absent_count_before'=>$absent,'absent_count_after'=>$case==='absent_info'?$q('SELECT COUNT(*) AS CNT FROM '.$p.'syllabus_evaluate WHERE UUID=?',[$post['uuid']])[0]['cnt']:null];if(strlen($entry['response'])>2097152)throw new RuntimeException('Response cap2MiB');file_put_contents(__DIR__.'/private-wire.jsonl',json_encode($entry,JSON_UNESCAPED_UNICODE)."\n",FILE_APPEND);chmod(__DIR__.'/private-wire.jsonl',0600);}catch(Throwable $e){file_put_contents(__DIR__.'/private-audit-error',hash('sha256',$e->getMessage()));chmod(__DIR__.'/private-audit-error',0600);}});$_SERVER['PATH_INFO']=$path;require __DIR__.'/init.php';\think\App::run()->send();
