Files
compras/integrations/sgf/operational/BudgetOverlay.php
T
2026-11-02 20:27:11 +02:00

35 lines
1.9 KiB
PHP

<?php
namespace Tempo\Purchasing\Delivery;
final class BudgetOverlay
{
public static function prepare(string $host): array
{
$path = 'app/Modules/Purchasing/BudgetAdapter.php';
$source = file_get_contents($host.'/'.$path);
$before = hash('sha256', $source);
$anchor = "public static function guard(): void\n {";
$source = str_replace("\r\n", "\n", $source);
if (substr_count($source, $anchor) !== 1) {
throw new \RuntimeException('Adaptador orçamental divergente.');
}
$source = str_replace($anchor, $anchor."\n if (config('purchasing-operational.enabled') === true) {\n \\Tempo\\Purchasing\\Delivery\\Installation::assertBudgetReady(DB::connection());\n return;\n }", $source);
$result = [$path => ['before_sha256' => $before, 'after_sha256' => hash('sha256', $source), 'contents' => $source]];
$path = 'app/Modules/Purchasing/BudgetWorkspace.php';
$source = file_get_contents($host.'/'.$path);
$before = hash('sha256', $source);
$anchor = 'public function command(User $user, string $action, array $input, string $key): array'."\n {";
$source = str_replace("\r\n", "\n", $source);
if (substr_count($source, $anchor) !== 1) {
throw new \RuntimeException('Workspace orçamental divergente.');
}
$source = str_replace($anchor, $anchor."\n if (config('purchasing-operational.enabled') === true) { abort_unless(in_array(\$action, ['create', 'approve'], true), 403, 'Movimentos orçamentais operacionais pertencem ao processo de origem.'); }", $source);
$source = str_replace("'synthetic_only' => true", "'synthetic_only' => config('purchasing-operational.enabled') !== true", $source);
$result[$path] = ['before_sha256' => $before, 'after_sha256' => hash('sha256', $source), 'contents' => $source];
return $result;
}
}