summaryrefslogtreecommitdiffstats
path: root/yamn_config.php
blob: 2959736e0b1246179ee7548ee1aae9801b7d84d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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]);
}