<?php
declare(strict_types=1);
function numericRepeatBytes($raw):bool{return is_string($raw)&&strlen($raw)===33&&substr($raw,0,32)==="<?php\n//000000000005\n exit();?>\n"&&substr($raw,32)==='1';}
function originalResponseRecord($response,$start,$end):array{return ['http_status'=>$response->getCode(),'headers'=>$response->getHeader(),'raw_response_body'=>$response->getContent(),'business_start'=>$start,'business_end'=>$end,'captured_microtime'=>microtime(true)];}
function preserveSendObserve($response,callable $save,callable $send,callable $observe,callable $error,$start,$end):void{
 $record=originalResponseRecord($response,$start,$end);$save($record);$send();
 try{$observe($record);}catch(Throwable $e){$error(['class'=>get_class($e),'message'=>$e->getMessage(),'file'=>$e->getFile(),'line'=>$e->getLine(),'original_response_preserved'=>true,'original_response_sent'=>true]);}
}
function includedProof():array{global $root;$pins=json_decode(file_get_contents(__DIR__.'/source-frozen-sha.json'),true)['files'];$included=[];foreach(get_included_files() as $f)if(strpos($f,$root.'/')===0){$n=substr($f,strlen($root)+1);$included[$n]=hash_file('sha256',$f);ck(isset($pins[$n])&&$pins[$n]===$included[$n],'Actual included immutable source '.$n);}return $included;}
function actualRepeatLock($app):array{global $runtime;$key='meal_direct_pay_'.CoreGate::$ids['AI_U1'].'_'.CoreGate::$ids['STORE_R1'];$file=$app->cache->store('file')->getCacheKey($key);ck(strpos($file,$runtime.'/cache/')===0&&is_file($file)&&!is_link($file),'Exact original repeat file');$raw=file_get_contents($file);ck(numericRepeatBytes($raw),'Original numeric FileCache TTL5/text1 bytes');return ['file'=>$file,'sha256'=>hash('sha256',$raw),'bytes'=>strlen($raw),'TTL'=>5,'payload'=>'1','mtime'=>filemtime($file)];}
