<?php
declare(strict_types=1);
date_default_timezone_set('Asia/Shanghai');$lane=getenv('ANALYSIS_LANE');$root=getenv('ANALYSIS_ROOT');$runtime=getenv('ANALYSIS_RUNTIME');$base=getenv('ANALYSIS_BASE');$dm=getenv('POC_DIALECT')==='dm';$check=static function($ok,$why){if(!$ok)throw new RuntimeException($why);};$marker='CDXTA10B92E';$operator=2147001621;
$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 Analysis PDO identity 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 identity');
$metadata=json_decode(file_get_contents(__DIR__.'/metadata-'.$lane.'.json'),true);$samples=json_decode(file_get_contents($runtime.'/metadata-samples.json'),true);$selected=end($samples['selected']);$check($metadata['complete_nonempty_candidate']&&$selected['infos_rows']>0&&$selected['recommend_rows']===1,'Ready natural unique linked sample');$tenant=$selected['store_id'];$staff=$selected['staff_id'];
$query=static function($sql,$args=[])use($db){$s=$db->prepare($sql);$s->execute($args);$rows=$s->fetchAll(PDO::FETCH_ASSOC);foreach($rows as &$r)foreach($r as &$v)if(is_resource($v))$v=stream_get_contents($v);return $rows;};
// Original DECIMALs are read as text on old PDO_DM; no float-rounding oracle.
$read=static function($table,$where='',$args=[],$order='')use($metadata,$dm,$query){$fields=[];foreach($metadata['metadata'][$table]['columns'] as $c){$k=strtolower($c['column_name']);$type=strtolower($c['data_type']);$id=$dm?'"'.strtoupper($k).'"':'`'.$k.'`';$fields[]=$dm&&in_array($type,['decimal','numeric','dec','number'],true)?'CAST('.$id.' AS VARCHAR(128)) AS '.$id:$id;}$rows=$query('SELECT '.implode(',',$fields).' FROM yoshop_'.$table.($where?' WHERE '.$where:'').($order?' ORDER BY '.$order:''),$args);foreach($rows as &$r)foreach($metadata['metadata'][$table]['columns'] as $c){$k=strtolower($c['column_name']);$type=strtolower($c['data_type']);if($r[$k]===null)continue;if(in_array($type,['int','integer','bigint','tinyint','smallint','bit'],true))$r[$k]=(int)$r[$k];elseif(in_array($type,['decimal','numeric','dec','number'],true))$r[$k]=bcadd((string)$r[$k],'0',(int)($dm?$c['data_scale']:$c['numeric_scale']));}return $rows;};
$boundary=json_decode(file_get_contents($base.'/__boundary'),true);$check(count($boundary['reflection'])===15&&$boundary['private_cache']&&$boundary['external_forbidden'],'Actual private runtime boundary');foreach($boundary['reflection'] as $f=>$v)$check($v['actual_private_path']&&hash_file('sha256',$root.'/'.$f)===$v['sha256'],'Actual source '.$f);$check($boundary['reflection']['app/common/database/DmBuilder.php']['sha256']==='58e1e79ce69881cc305c6fd33adec0e9a3d030ac15b4c00ae464cbaa4cce2b59','Expected main 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]);
