37 lines
1.8 KiB
PHP
37 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Tempo\Purchasing\Delivery;
|
|
|
|
final class BootOverlay
|
|
{
|
|
public static function prepare(string $host): array
|
|
{
|
|
$result = [];
|
|
foreach (['app/Providers/AppServiceProvider.php', 'app/Shared/Context/ModuleNavigation.php'] as $path) {
|
|
$source = file_get_contents($host.'/'.$path);
|
|
$hash = hash('sha256', $source);
|
|
$source = str_replace("\r\n", "\n", $source);
|
|
if (str_ends_with($path, 'AppServiceProvider.php')) {
|
|
$old = '$this->app->scoped(CompanyContext::class';
|
|
$new = "if (is_file(base_path('packages/internal-requisitions/bootstrap.php'))) { require_once base_path('packages/internal-requisitions/bootstrap.php'); }\n ".$old;
|
|
$source = self::replace($source, $old, $new);
|
|
$source = self::replace($source, "public function boot(): void\n {", "public function boot(): void\n {\n if (is_file(base_path('packages/internal-requisitions/bootstrap.php'))) { \$this->loadRoutesFrom(base_path('packages/internal-requisitions/integrations/sgf/operational/routes.php')); }");
|
|
} else {
|
|
$source = self::replace($source, "'purchasing'=>['purchasing_budget.', 'supplier_payables.']", "'purchasing'=>['purchasing_budget.', 'purchasing_requisitions.', 'supplier_payables.']");
|
|
}
|
|
$result[$path] = ['before_sha256' => $hash, 'after_sha256' => hash('sha256', $source), 'contents' => $source];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private static function replace(string $source, string $old, string $new): string
|
|
{
|
|
if (substr_count($source, $old) !== 1) {
|
|
throw new \RuntimeException('Arranque/navegação do host divergiu; reconciliar antes de preparar.');
|
|
}
|
|
|
|
return str_replace($old, $new, $source);
|
|
}
|
|
}
|