This commit is contained in:
2025-12-10 00:32:10 +01:00
parent eba2625693
commit fc13c4f5c2
4 changed files with 180 additions and 3 deletions

View File

@@ -7,12 +7,12 @@
// -----------------------------------------------------------
// Try to load primary environment bootstrap.
$bootstrapCandidates = [__DIR__ . '/config.php'];
$bootstrapCandidates = [__DIR__ . '/versions.php'];
$envHint = getenv('APP_ENV') ?: (getenv('APP_ENV_FILE') ?: null);
if ($envHint) {
$bootstrapCandidates[] = __DIR__ . '/' . $envHint . '/config.php';
}
$bootstrapCandidates[] = __DIR__ . '/staging/config.php';
$bootstrapCandidates[] = __DIR__ . '/prod/config.php';
$bootstrapLoaded = false;
foreach ($bootstrapCandidates as $bootstrap) {
if ($bootstrap && is_file($bootstrap)) {
@@ -35,6 +35,50 @@ if (is_file($emailtemplateConfigPath)) {
$GLOBALS['app_env'] = APP_ENV;
$GLOBALS['app_base_url'] = APP_URL_PRIMARY;
$GLOBALS['app_api_base'] = $apiBaseUrl;
$GLOBALS['app_version'] = "{$mainversion}.{$subversion}.{$patchversion}";
if (!function_exists('render_app_version_badge')) {
function render_app_version_badge(): void
{
if (php_sapi_name() === 'cli') {
return;
}
static $badgeRendered = false;
if ($badgeRendered) {
return;
}
$badgeRendered = true;
$version = $GLOBALS['app_version'] ?? null;
if (!$version) {
return;
}
$versionText = htmlspecialchars((string)$version, ENT_QUOTES, 'UTF-8');
echo <<<HTML
<style>
.app-version-badge{position:fixed;right:12px;bottom:12px;z-index:2147483000;font-size:12px;font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#0f172a;background:rgba(248,250,252,.85);border:1px solid rgba(148,163,184,.6);border-radius:999px;padding:4px 10px;box-shadow:0 8px 20px rgba(15,23,42,.15);backdrop-filter:blur(6px);}
@media print {.app-version-badge{display:none}}
</style>
<script>
(function(){
var prev=document.querySelector('.app-version-badge');
if(prev){prev.remove();}
var badge=document.createElement('div');
badge.className='app-version-badge';
badge.textContent='v {$versionText}';
(window.requestAnimationFrame?requestAnimationFrame(function(){document.body?document.body.appendChild(badge):document.addEventListener('DOMContentLoaded',function(){document.body.appendChild(badge);});}):document.addEventListener('DOMContentLoaded',function(){document.body.appendChild(badge);}));
})();
</script>
HTML;
}
}
if (!defined('APP_VERSION_BADGE_REGISTERED')) {
register_shutdown_function('render_app_version_badge');
define('APP_VERSION_BADGE_REGISTERED', true);
}
// -----------------------------------------------------------
// set cookie / session parameters

4
config/prod/versions.php Normal file
View File

@@ -0,0 +1,4 @@
<?php
$mainversion = 1;
$subversion = 0;
$patchversion = 1;

View File

@@ -0,0 +1,4 @@
<?php
$mainversion = 1;
$subversion = 0;
$patchversion = 1;