Refactor configuration handling: implement dynamic loading of config and cache paths for improved security and flexibility in Docker environments

This commit is contained in:
David Dyer committed 2026-10-25 16:49:43 -04:00
1 parent c7b836bcf2
commit bb65ecd43c
7 files changed
+53 -12

No files matched your search

+5 -2
View File
@@ -20,7 +20,11 @@ function fritz_google_reviews(): array {
return $fallback;
}
$cacheFile = __DIR__ . '/../cache/google-reviews.json';
// In Docker, FITZ_CACHE_DIR points into the writable data/ mount, outside
// the web root, so deploys don't wipe it and www/ can stay read-only to
// www-data. Local dev falls back to cache/ in the project root.
$cacheDir = getenv('FITZ_CACHE_DIR') ?: __DIR__ . '/../cache';
$cacheFile = $cacheDir . '/google-reviews.json';
if (is_file($cacheFile)) {
$cached = json_decode((string) file_get_contents($cacheFile), true);
@@ -33,7 +37,6 @@ function fritz_google_reviews(): array {
$fresh = fritz_fetch_google_reviews($fallback);
$fresh['fetched_at'] = time();
$cacheDir = dirname($cacheFile);
if (!is_dir($cacheDir)) {
@mkdir($cacheDir, 0775, true);
}
+11
View File
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
/**
* Loads the site config. In Docker, FITZ_CONFIG_PATH points outside the
* web root (see docker-compose.yaml), so a deploy that replaces www/ can
* never overwrite or ship it. Local dev falls back to config.php in the
* project root.
*/
require getenv('FITZ_CONFIG_PATH') ?: __DIR__ . '/../config.php';