-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.php
More file actions
44 lines (38 loc) · 1.19 KB
/
env.php
File metadata and controls
44 lines (38 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
if (!isset($GLOBALS['__env_loaded'])) {
$GLOBALS['__env_loaded'] = true;
$env_path = __DIR__ . '/.env';
if (is_readable($env_path)) {
$lines = file($env_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
$line = trim($line);
if ($line === '' || strpos($line, '#') === 0) {
continue;
}
$parts = explode('=', $line, 2);
if (count($parts) !== 2) {
continue;
}
$key = trim($parts[0]);
$value = trim($parts[1]);
if ($value !== '' && (
($value[0] === '"' && substr($value, -1) === '"') ||
($value[0] === "'" && substr($value, -1) === "'")
)) {
$value = substr($value, 1, -1);
}
if ($key !== '') {
putenv($key . '=' . $value);
$_ENV[$key] = $value;
$_SERVER[$key] = $value;
}
}
}
}
if (!function_exists('env_value')) {
function env_value($key, $default = null)
{
$value = getenv($key);
return $value === false ? $default : $value;
}
}