Skip to content

Commit 6e64932

Browse files
committed
feat: perform basic parsing on env values
1 parent b9f4896 commit 6e64932

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Global
22
.phpunit*
33
.composer
4+
Experimental
45
composer.lock
56
package-lock.json
67
.phpunit.result.cache

src/functions.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,34 @@ function app(): Leaf\App
3030
function _env($key, $default = null)
3131
{
3232
$env = array_merge(getenv() ?? [], $_ENV ?? []);
33+
$value = $env[$key] ??= null;
3334

34-
return $env[$key] ??= $default;
35+
if ($value === null) {
36+
return $default;
37+
}
38+
39+
switch (strtolower($value)) {
40+
case 'true':
41+
case '(true)':
42+
return true;
43+
44+
case 'false':
45+
case '(false)':
46+
return false;
47+
48+
case 'empty':
49+
case '(empty)':
50+
return '';
51+
52+
case 'null':
53+
case '(null)':
54+
return;
55+
}
56+
57+
if (strpos($value, '"') === 0 && strpos($value, '"') === strlen($value) - 1) {
58+
return substr($value, 1, -1);
59+
}
60+
61+
return $value;
3562
}
3663
}

0 commit comments

Comments
 (0)