<?php
$lane=getenv('FR_LANE');$root=getenv('FR_ROOT');
$expected=$lane==='B'?'/tmp/zhct-http-store-mysql.dQTTBP':'/tmp/zhct-dm-poc-20260928.fcpiiN/store';
if(!in_array($lane,['B','C'],true)||$root!==$expected||is_link($root)){http_response_code(503);exit;}
$path=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);
if(!in_array($path,['/api/finance/visitor/flows','/api/cashRefund/list','/api/cashRefund/detail'],true)||$_SERVER['REQUEST_METHOD']!=='GET'){http_response_code(403);exit;}
require $root.'/env.php';
if(!function_exists('json')){function json($data=[],$code=200,array $header=[],$options=[]){return \think\Response::create($data,'json',$code,$header,$options);}}
if(getenv('POC_EXTERNAL_STUBS')!=='1'){http_response_code(503);exit;}
require $root.'/external_stubs.php';define('APP_PATH',$root.'/application/');define('RUNTIME_PATH',__DIR__.'/runtime/');require $root.'/thinkphp/base.php';
require __DIR__.'/SqlCoverageRecorder.php';
$observer=new SqlCoverageRecorder(__DIR__.'/events-'.$lane.'.jsonl',$root,'PILOT_FINANCE_READ_'.strtoupper(str_replace('/','_',$path)));
\think\App::initCommon();\think\Request::instance()->pathinfo();
\think\Log::init(['type'=>'File','path'=>__DIR__.'/runtime/safe-log/','level'=>['never_persist_raw_application_logs']]);
\think\Config::set(['type'=>'File','path'=>__DIR__.'/cache/','prefix'=>'FR10_'],'cache');
$database=require $root.'/application/database.php';$debug=!($lane==='B'&&$path==='/api/finance/visitor/flows');$database['debug']=$debug;$database['sql_explain']=false;
$database['ai_zhct']['debug']=$debug;$database['ai_zhct']['sql_explain']=false;
\think\Config::set($database,'database');\think\Db::clear();\think\Db::listen([$observer,'observe']);register_shutdown_function([$observer,'finish']);
\think\App::run()->send();
