Update gitignore to exclude config files, refactor index.php for dynamic configuration file loading and caching.
This commit is contained in:
parent
2ffac2254c
commit
8ac31b0092
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
config.php
|
||||
config*.php*
|
||||
vendor/
|
||||
twig_cache/
|
||||
metrics_cache.json
|
||||
|
16
index.php
16
index.php
@ -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, [
|
||||
|
Loading…
Reference in New Issue
Block a user