<?php
declare(strict_types=1);
$root=getenv('SM7_ROOT');$parent=getenv('SM7_PARENT');$runtime=getenv('SM7_RUNTIME');$path=parse_url($_SERVER['REQUEST_URI']??'',PHP_URL_PATH);$allowed=['/p/date_menu/hardwareInfo','/p/dateMenu/checkMenuList'];
if(!(($path==='/__poc_boundary'&&$_SERVER['REQUEST_METHOD']==='GET')||(in_array($path,$allowed,true)&&$_SERVER['REQUEST_METHOD']==='POST'))){http_response_code(403);exit;}
$_SERVER['PATH_INFO']=$path;require $parent.'/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'||getenv('POC_REAL_QUEUE')!=='0'){http_response_code(503);exit;}require $parent.'/external_stubs.php';define('APP_PATH',$root.'/application/');define('RUNTIME_PATH',$runtime.'/runtime/');require $parent.'/thinkphp/base.php';
\think\App::initCommon();\think\Request::instance()->pathinfo();\think\Log::init(['type'=>'File','path'=>$runtime.'/safe-log/','level'=>['no_raw_application_log']]);\think\Config::set(['type'=>'File','path'=>$runtime.'/cache/','prefix'=>'HC10_'],'cache');\think\Config::set('redis',[]);
$db=require $parent.'/application/database.php';$originalDebug=$db['debug']??null;$db['debug']=true;\think\Config::set($db,'database');\think\Db::clear();
foreach(['app\\p\\controller\\DateMenu'=>'application/p/controller/DateMenu.php','app\\p\\logic\\DateMenu'=>'application/p/logic/DateMenu.php'] as $class=>$f){if(realpath((new ReflectionClass($class))->getFileName())!==realpath($root.'/'.$f)){http_response_code(503);exit;}}
if($path==='/__poc_boundary'){echo json_encode(['private_source_reflection'=>true,'file_cache'=>true,'redis_disabled'=>\think\Config::get('redis')===[],'external_stubs'=>class_exists(\app\common\Serve::class,false),'real_queue'=>false,'original_debug'=>$originalDebug,'diagnostic_query_observation_debug'=>true,'default_input_filter'=>\think\Config::get('default_filter')]);exit;}
$actor=json_decode(file_get_contents($runtime.'/actor-private.json'),true);require_once $root.'/application/base/Security.php';$decoded=\app\base\Security::decrypt((string)($_SERVER['HTTP_TOKEN']??''));$parts=explode("\t",(string)$decoded);
if((int)($parts[0]??0)!==$actor['id']||($parts[1]??'')!==$actor['uuid']||($parts[2]??'')!==$actor['marker']||($parts[3]??'')!=='0'){http_response_code(403);exit;}
$fixture=json_decode(file_get_contents($runtime.'/fixture-private.json'),true);$seed=$fixture['seed'];$p=$_POST;
if($path===$allowed[0]){$ok=(string)($p['staff_uuid']??'')===$seed['staff']&&(string)($p['menu_date']??'')===$seed['date']&&(string)($p['meal_times']??'')==='1'&&(string)($p['type']??'')==='1'&&!array_diff(array_keys($p),['staff_uuid','menu_date','meal_times','type']);}
else{$ok=(string)($p['department_uuid']??'')===$seed['department']&&(string)($p['date']??'')===$seed['date']&&(string)($p['meal_times']??'')==='1'&&(string)($p['page']??'')==='1'&&(string)($p['page_size']??'')==='5'&&in_array($p['staff_name']??'',['',$seed['marker'],$seed['marker'].'员"测\''],true)&&!array_diff(array_keys($p),['department_uuid','date','meal_times','page','page_size','staff_name']);}
if(!$ok){http_response_code(403);exit;}$scenario=$_SERVER['HTTP_X_PILOT_SCENARIO']??'';if(!preg_match('/^PILOT_HC_[A-Z0-9_]{1,40}$/D',$scenario)){http_response_code(403);exit;}
if(getenv('SM7_LANE')==='B'){$actualChildren=(new \app\model\Department())->getChildUuids($seed['department']);if($actualChildren!==[$seed['department']]){http_response_code(409);exit;}file_put_contents($runtime.'/child-uuid-'.str_replace('PILOT_HC_','',$scenario).'-private.json',json_encode($actualChildren));}
require __DIR__.'/SqlCoverageRecorder.php';$r=new SqlCoverageRecorder($runtime.'/queries.jsonl',realpath($root),$scenario);\think\Db::listen(static function($sql,$time=null)use($r){if(strpos($sql,'CONNECT:')!==0){$r->observe($sql,$time);}});register_shutdown_function([$r,'finish']);\think\App::run()->send();
