Files
SGF/scripts/build-receipt-runtime.php
2026-11-04 09:37:20 +02:00

17 lines
1.9 KiB
PHP

<?php
// Package transport only: rewrite PHP namespace tokens, never rule expressions or strings.
[$script,$source,$target]=$argv;
if(realpath($source)!==realpath(dirname(__DIR__).'/../compras')||!str_starts_with(str_replace('\\','/',$target),'C:/laragon/data/sgf-tempo/run/modular-regression-')||file_exists($target))throw new LogicException('Fresh private bundle required');
mkdir($target,0777,true);$files=[];$originals=[];
foreach(['app'=>$source.'/app','fortify'=>$source.'/vendor/laravel/fortify/src']as$prefix=>$directory){
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory,FilesystemIterator::SKIP_DOTS))as$file){
if(!$file->isFile()||$file->getExtension()!=='php')continue;if($file->isLink())throw new LogicException('Linked source refused');$relative=$prefix.'/'.str_replace('\\','/',substr($file->getPathname(),strlen($directory)+1));$raw=file_get_contents($file->getPathname());$text='';
foreach(token_get_all($raw)as$token){if(!is_array($token)){$text.=$token;continue;}[$type,$value]=$token;
if($prefix==='app'&&in_array($type,[T_NAME_QUALIFIED,T_NAME_FULLY_QUALIFIED],true))$value=preg_replace('/^(\\\\?)App\\\\/','$1Tempo\\Purchasing\\Embedded\\',$value);
$text.=$value;
}
$destination=$target.'/'.$relative;if(!is_dir(dirname($destination)))mkdir(dirname($destination),0777,true);file_put_contents($destination,$text);$files[$relative]=hash('sha256',$text);$originals[$relative]=hash('sha256',$raw);
}
}
ksort($files);ksort($originals);file_put_contents($target.'/manifest.json',json_encode(['format'=>'sgf.receipt.native-namespace.v1','files'=>$files,'originals'=>$originals,'transformation'=>'Only App-qualified PHP name tokens become Tempo\\Purchasing\\Embedded; strings and rule expressions unchanged.'],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($files)." original PHP files packaged with namespace-only adaptation.\n";