version = $v; if ($k === 'rev') $m->rev = $v; if ($k === 'updated') $m->updated = $v; } } // 2) Fallback: .env APP_VERSION if ($m->version === 'dev' && ($envVer = env('APP_VERSION'))) { $m->version = trim($envVer); } // 3) Fallback: Git (ohne "-dirty") if ($m->rev === '' || $m->version === 'dev') { $head = $basePath.'/.git/HEAD'; if (is_file($head)) { $ref = trim((string)@file_get_contents($head)); if (Str::startsWith($ref, 'ref:')) { $refFile = $basePath.'/.git/'.substr($ref, 5); $commit = @file_get_contents($refFile); } else { $commit = $ref; } $m->rev = $m->rev ?: trim((string)$commit); if ($m->version === 'dev') { $tag = @shell_exec('git -C '.escapeshellarg($basePath).' describe --tags --abbrev=0 2>/dev/null'); $m->version = $tag ? trim($tag) : 'dev'; } } } // Sauber: "-dirty" entfernen $m->version = preg_replace('/-dirty$/', '', $m->version); // Kurz-Commit $m->short = $m->rev ? substr($m->rev, 0, 7) : ''; return $m; } public function toArray(): array { return [ 'version' => $this->version, 'rev' => $this->rev, 'short' => $this->short, 'updated' => $this->updated, ]; } }