This commit is contained in:
parent
99d94eb54d
commit
7fe9f79d0e
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Plugin\Helper;
|
||||
|
||||
function loadEnVars(array $map, array $defaults = [])
|
||||
{
|
||||
$container = [];
|
||||
|
||||
foreach ($map as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$container[$key] = loadEnVars($value);
|
||||
} else {
|
||||
$data = getenv($value);
|
||||
|
||||
if (false === $data) {
|
||||
$data = $defaults[$value] ?? null;
|
||||
}
|
||||
|
||||
if (str_ends_with($key, '_at') && ctype_digit($data)) {
|
||||
$date = new \DateTime();
|
||||
$date->setTimestamp((int) $data);
|
||||
$data = $date;
|
||||
} elseif (str_starts_with($key, 'is_')) {
|
||||
if (in_array(strtolower($data), ['1', 'true', 'yes'])) {
|
||||
$data = true;
|
||||
} elseif (in_array(strtolower($data), ['0', 'false', 'no'])) {
|
||||
$data = false;
|
||||
} else {
|
||||
$data = $defaults[$value] ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
$container[$key] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
Loading…
Reference in a new issue