<?php
declare(strict_types=1);
try{require __DIR__.'/bootstrap.php';$started=microtime(true);$path=parse_url($_SERVER['REQUEST_URI']??'',PHP_URL_PATH);$scenario=$_SERVER['HTTP_X_PILOT_SCENARIO']??'';if(($_SERVER['REQUEST_METHOD']??'')!=='GET'||!preg_match('#^/(store|terminal)/(Home/data|statistics\.Data/(data|survey)|order\.Export/list)$#D',(string)$path)||!preg_match('/^PILOT_DS_[A-Z0-9_]{1,60}$/D',$scenario)){http_response_code(403);echo '{"denied":true}';return;}
ini_set('log_errors','1');ini_set('error_log',$runtime.'/private-errors.log');$_SERVER['SCRIPT_FILENAME']=$root.'/public/index.php';$_SERVER['SCRIPT_NAME']='/index.php';$_SERVER['PHP_SELF']='/index.php';$app=commentApp($root,$runtime);$hosts=['store.dashboard.invalid'=>2147001111,'terminal.dashboard.invalid'=>2147001112];$app->env->set('store.host',$hosts);$check(isset($hosts[$app->request->host()])&&getStoreId()===$hosts[$app->request->host()],'Own host tenant gate');$before=$own();$protected=$protect();$cfg=$app->config->get('database');foreach($cfg['connections'] as &$c){$c['trigger_sql']=true;$c['debug']=false;}unset($c);$app->config->set($cfg,'database');$app->db->setConfig($app->config);
require __DIR__.'/SqlCoverageRecorder.php';$rec=new SqlCoverageRecorder($runtime.'/queries.jsonl',$root,$scenario);$ops=[];$app->db->listen(static function($sql,$elapsed=null)use($rec,$runtime,$scenario,&$ops){if(strpos((string)$sql,'CONNECT:')===0)return;$op=SqlCoverageRecorder::fingerprint($sql)['operation'];$ops[]=$op;if(!in_array($op,['select','other'],true))throw new RuntimeException('Read-only business DML observed');$rec->observe($sql,$elapsed);file_put_contents($runtime.'/private-sql.jsonl',json_encode(['scenario'=>$scenario,'sql'=>$sql,'layer'=>'ThinkPHP framework listener debug interpolation; NOT PDO queryString/server audit'],JSON_UNESCAPED_UNICODE)."\n",FILE_APPEND|LOCK_EX);chmod($runtime.'/private-sql.jsonl',0600);});register_shutdown_function([$rec,'finish']);
$http=$app->http;$response=$http->run();$hashes=[];$suffix=['controller/Home.php','controller/statistics/Data.php','controller/order/Export.php','service/Home.php','service/statistics/Data.php','service/statistics/data/Survey.php','service/statistics/data/Trade7days.php','service/statistics/data/GoodsRanking.php','service/statistics/data/UserExpendRanking.php','model/Order.php','model/User.php','model/Goods.php','model/order/Export.php','model/recharge/Order.php'];$files=['app/common/database/DmBuilder.php','cores/BaseModel.php'];foreach(['store','terminal'] as $m)foreach($suffix as $f)$files[]='app/'.$m.'/'.$f;foreach($files as $f){$class=str_replace('/','\\',substr($f,0,-4));$actual=(new ReflectionClass($class))->getFileName();$check(realpath($actual)===realpath($root.'/'.$f),'Actual isolated source root');$hashes[$f]=hash_file('sha256',$actual);}$after=$own();$check($before===$after,'All23 own tables read-only exact');$check($protected===$protect(),'Natural/default read-only exact');$fixture=json_decode(file_get_contents($runtime.'/fixture-journal.json'),true);$check($after===$fixture['after'],'All proved fixture rows remain exact');$wire=['scenario'=>$scenario,'method'=>'GET','path'=>$path,'http_status'=>$response->getCode(),'elapsed_ms'=>(microtime(true)-$started)*1000,'raw'=>$response->getContent(),'before'=>$before,'original'=>$after,'protect_before'=>$protected,'protect_after'=>$protect(),'source_sha256'=>$hashes,'operations'=>$ops,'SQL_evidence_layer'=>'framework listener debug interpolation, independent PDO physical row effects separately'];file_put_contents($runtime.'/private-wire.jsonl',json_encode($wire,JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION)."\n",FILE_APPEND|LOCK_EX);chmod($runtime.'/private-wire.jsonl',0600);$response->send();$http->end($response);
}catch(Throwable $e){if(isset($persist))$persist('harness-failure.json',['class'=>get_class($e),'message'=>$e->getMessage(),'file'=>$e->getFile(),'line'=>$e->getLine()]);http_response_code(500);header('Content-Type: application/json');echo json_encode(['harness_error'=>get_class($e),'message'=>$e->getMessage()]);}
