<?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/dateMenu/getDishes','/p/dateMenu/getRecipeInfo','/p/date_menu/hardwareInfo','/p/dateMenu/checkMenuList','/p/equipment/VersionList','/p/equipment/versionRead','/p/equipment/consumeList'];
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'=>'SM7_'],'cache');\think\Config::set('redis',[]);
$database=require $parent.'/application/database.php';$originalDebug=$database['debug']??null;$database['debug']=true;\think\Config::set($database,'database');\think\Db::clear();
foreach(['app\\p\\controller\\DateMenu'=>'application/p/controller/DateMenu.php','app\\p\\controller\\Equipment'=>'application/p/controller/Equipment.php','app\\p\\logic\\DateMenu'=>'application/p/logic/DateMenu.php','app\\p\\logic\\Equipment'=>'application/p/logic/Equipment.php'] as $class=>$f){$actual=(new ReflectionClass($class))->getFileName();if(realpath($actual)!==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]);exit;}
$actor=json_decode(file_get_contents($runtime.'/actor-private.json'),true);$token=(string)($_SERVER['HTTP_TOKEN']??'');require_once $root.'/application/base/Security.php';$decoded=\app\base\Security::decrypt($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;}
$scenario=$_SERVER['HTTP_X_PILOT_SCENARIO']??'';if(!preg_match('/^PILOT_SM7_[A-Z0-9_]{1,40}$/D',$scenario)){http_response_code(403);exit;}
require __DIR__.'/SqlCoverageRecorder.php';$recorder=new SqlCoverageRecorder($runtime.'/queries.jsonl',realpath($root),$scenario);\think\Db::listen(static function($sql,$time=null)use($recorder){if(strpos($sql,'CONNECT:')!==0){$recorder->observe($sql,$time);}});register_shutdown_function([$recorder,'finish']);
\think\App::run()->send();
