Update gitignore to exclude config files, refactor index.php for dynamic configuration file loading and caching.

This commit is contained in:
Jeroen De Meerleer 2024-06-05 08:28:57 +02:00
parent 2ffac2254c
commit 8ac31b0092
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 13 additions and 6 deletions

3
.gitignore vendored
View File

@ -1,4 +1,3 @@
config.php
config*.php*
vendor/
twig_cache/
metrics_cache.json

View File

@ -1,8 +1,16 @@
<?php
require 'vendor/autoload.php';
require 'config.php';
if(file_exists('metrics_cache.json')) {
$oldconfig = json_decode(file_get_contents('metrics_cache.json'), true);
$configFile = getenv('CONFIG_FILE') ?: 'config.php';
$cacheFile = $configFile . '.cache.json';
if (file_exists($configFile)) {
require ($configFile);
} else {
echo ("Configuration file not found: " . $configFile);
exit(1);
}
if(file_exists($cacheFile)) {
$oldconfig = json_decode(file_get_contents($cacheFile), true);
} else {
$oldconfig = [];
}
@ -95,7 +103,7 @@ if(php_sapi_name() == 'cli' || $_SERVER["REQUEST_URI"] == '/metrics') {
}
}
file_put_contents('metrics_cache.json', json_encode($config, JSON_PRETTY_PRINT));
file_put_contents($cacheFile, json_encode($config, JSON_PRETTY_PRINT));
$loader = new \Twig\Loader\FilesystemLoader('templates');
$twig = new \Twig\Environment($loader, [