Files
SGF/scripts/sgf-native-bindings.php
T
2026-11-11 09:00:17 +02:00

13 lines
1.7 KiB
PHP

<?php
$book=$argv[1]??'regression';require __DIR__.'/sgf-single-bootstrap.php';
$profiles=json_decode(file_get_contents($s['root'].'/single-profiles.json'),true);
$ledger=json_decode(file_get_contents($s['root'].'/single-native-ledger.json'),true);
$original=json_decode(file_get_contents($s['root'].'/binding.json'),true);$template=$original['bindings'][implode(':',array_values($f['scope'])).':'.$f['issuer']];
$policy=App\Shared\Installation\SyntheticProfiles::policy();$bindings=[];
foreach($policy['financial_source_policy']['native_finance_bindings'] as $key=>$actor){$user=$profiles['profiles'][$key]['user_id'];$bindings[implode(':',array_values($f['scope'])).':'.$user]=array_replace($template,['actor_id'=>$actor,'warehouse_ids'=>[$nf['warehouse'],$ledger['warehouse_id']]]);}
// Additional Stock warehouse is an explicit approved supplement, not a mutation of purchasing bindings.
$stockMap=['composition'=>$tag,'warehouse_bindings'=>[implode(':',array_values($f['scope'])).':'.$f['validator']=>[$nf['warehouse'],$ledger['warehouse_id']]]];
$paths=['single-bindings.json'=>['composition'=>$tag,'bindings'=>$bindings],'stock-operations-binding.json'=>$stockMap];$pins=[];
foreach($paths as $file=>$data){$target=$s['root'].'/'.$file;$raw=json_encode($data,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR);if(is_file($target)&&file_get_contents($target)!==$raw)throw new LogicException('Preserve differing private binding: '.$file);file_put_contents($target,$raw);$pins[$file]=hash_file('sha256',$target);}
file_put_contents($s['root'].'/single-binding-pins.json',json_encode($pins,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode(['passed'=>true,'book'=>$book,'new_profiles'=>count($bindings),'original_bindings_unchanged'=>true]).PHP_EOL;