summaryrefslogtreecommitdiffstats
path: root/yamn_config.php
diff options
context:
space:
mode:
Diffstat (limited to 'yamn_config.php')
-rw-r--r--yamn_config.php15
1 files changed, 15 insertions, 0 deletions
diff --git a/yamn_config.php b/yamn_config.php
new file mode 100644
index 0000000..2959736
--- /dev/null
+++ b/yamn_config.php
@@ -0,0 +1,15 @@
+<?php
+declare(strict_types=1);
+
+function yamnConfig(string $key, string $fallback = ''): string
+{
+ $path = getenv('YAMN_CONFIG_FILE') ?: '/etc/yamnweb/yamnweb.env';
+ if (!is_readable($path)) {
+ return getenv($key) !== false ? (string)getenv($key) : $fallback;
+ }
+ $values = parse_ini_file($path, false, INI_SCANNER_RAW);
+ if (!is_array($values) || !isset($values[$key]) || !is_string($values[$key])) {
+ return getenv($key) !== false ? (string)getenv($key) : $fallback;
+ }
+ return trim($values[$key]);
+}