From fc6bb2d1b523e30d77c20271592aaba68cfb94b4 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 17 Jan 2024 20:19:13 +0000 Subject: [PATCH] [core] allow sys-config settings to come from the environment --- core/sys_config.php | 12 +++++++++++- index.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/sys_config.php b/core/sys_config.php index d6b7825b..d41e1a66 100644 --- a/core/sys_config.php +++ b/core/sys_config.php @@ -9,7 +9,8 @@ namespace Shimmie2; * Shimmie will set the values to their defaults * * All of these can be over-ridden by placing a 'define' in - * data/config/shimmie.conf.php + * data/config/shimmie.conf.php, or by setting an environment + * variable SHM_{$name} (eg SHM_DATABASE_DSN) * * Do NOT change them in this file. These are the defaults only! * @@ -20,6 +21,15 @@ namespace Shimmie2; function _d(string $name, mixed $value): void { if (!defined($name)) { + $env = getenv("SHM_{$name}"); + if ($env !== false) { + try { + $value = json_decode($env); + } + catch(\Exception $e) { + $value = $env; + } + } define($name, $value); } } diff --git a/index.php b/index.php index 1d02f036..8b3c03a2 100644 --- a/index.php +++ b/index.php @@ -23,7 +23,7 @@ if (!file_exists("vendor/")) { ); } -if (!file_exists("data/config/shimmie.conf.php")) { +if (!file_exists("data/config/shimmie.conf.php") && !getenv("SHM_DATABASE_DSN")) { require_once "core/install.php"; install(); exit;