<?php
declare(strict_types=1);
date_default_timezone_set('Asia/Shanghai');$lane=getenv('PAGE_LANE');$runtime=getenv('PAGE_RUNTIME');$root=getenv('PAGE_ROOT');$base=getenv('PAGE_BASE');$dm=getenv('POC_DIALECT')==='dm';$marker='CDXPG10E7A2';$tenants=['store'=>2147001521,'terminal'=>2147001522];$check=static function($ok,$why){if(!$ok)throw new RuntimeException($why);};
$connect=static function()use($dm){try{return new PDO($dm?'dm:host=127.0.0.1;port=5238;schema=AIZHCT_APP':'mysql:host='.getenv('POC_AI_HOST').';port='.getenv('POC_AI_PORT').';dbname='.getenv('POC_AI_SCHEMA').';charset=utf8',getenv('POC_AI_USER'),getenv('POC_AI_PASSWORD'),[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,PDO::ATTR_CASE=>PDO::CASE_LOWER]);}catch(Throwable $e){throw new RuntimeException('Private Page DB connection failed');}};
$db=$connect();$check($dm?$db->query("SELECT SYS_CONTEXT('USERENV','CURRENT_SCHEMA') FROM DUAL")->fetchColumn()==='AIZHCT_APP':($db->query('SELECT DATABASE()')->fetchColumn()===getenv('POC_AI_SCHEMA')&&strpos($db->query('SELECT VERSION()')->fetchColumn(),'5.6.')===0),'Actual DB identity');
$query=static function($sql,$args=[])use($db){$s=$db->prepare($sql);$s->execute($args);$r=$s->fetchAll(PDO::FETCH_ASSOC);foreach($r as &$row)foreach($row as &$v)if(is_resource($v))$v=stream_get_contents($v);return $r;};
$gate=json_decode(file_get_contents(__DIR__.'/structure-'.$lane.'.json'),true);$check($gate['lane']===$lane&&$gate['business_dml']===0&&$gate['foreign_keys']===0&&$gate['triggers']===0&&$gate['own_collision']===0,'Live metadata/FK/trigger/collision gate');$cols=array_column($gate['columns'],'column_name');$cols=array_map('strtolower',$cols);sort($cols);$want=['page_id','page_type','page_name','page_data','is_delete','store_id','create_time','update_time'];sort($want);$check($cols===$want,'Exact original Page column set');
require __DIR__.'/metadata_gate.php';assertPageMetadata($gate,$dm);
$boundary=json_decode(file_get_contents($base.'/__poc_boundary'),true);$check($boundary['private_cache']&&$boundary['external_forbidden'],'Runtime isolation');foreach($boundary['hashes'] as $f=>$sha)$check(hash_file('sha256',$root.'/'.$f)===$sha,'Actual source '.$f);$check($boundary['hashes']['app/common/database/DmBuilder.php']==='58e1e79ce69881cc305c6fd33adec0e9a3d030ac15b4c00ae464cbaa4cce2b59','Current narrow builder source');
define('TP_ENV','poc');define('BUSINESS','aizhct');define('ENTERPRISE_NO','10001');require $root.'/vendor/autoload.php';spl_autoload_register(static function($class)use($root){foreach(['app\\'=>'app/','cores\\'=>'cores/'] as $prefix=>$dir)if(strpos($class,$prefix)===0){$f=$root.'/'.$dir.str_replace('\\','/',substr($class,strlen($prefix))).'.php';if(is_file($f))require $f;}},true,true);$app=new \think\App($root);$app->setEnvName('poc');$app->setRuntimePath($runtime.'/fixture-runtime/');$app->initialize();$cache=new \think\cache\driver\File($app,['path'=>$runtime.'/cache/','prefix'=>'','expire'=>0]);
$snapshot=static function()use($connect){$p=$connect();$s=$p->query('SELECT * FROM yoshop_page WHERE store_id NOT IN (2147001521,2147001522) ORDER BY page_id');$h=hash_init('sha256');$n=0;while($r=$s->fetch(PDO::FETCH_ASSOC)){foreach($r as &$v)if(is_resource($v))$v=stream_get_contents($v);unset($v);hash_update($h,serialize($r));$n++;}return ['rows'=>$n,'sha256'=>hash_final($h)];};
