-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcore.php
More file actions
32 lines (27 loc) · 1.15 KB
/
Copy pathcore.php
File metadata and controls
32 lines (27 loc) · 1.15 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
<?php
// composer.json autoload.files also loads this file, so guard against a second
// require (which would otherwise redefine CORE_PATH).
if (defined('CORE_PATH')) {
return;
}
define('CORE_PATH', dirname(__FILE__));
$dotenvPath = CORE_PATH . '/.env';
if (is_file($dotenvPath)) {
foreach (file($dotenvPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [] as $line) {
$line = trim($line);
if ($line === '' || str_starts_with($line, '#') || !str_contains($line, '=')) {
continue;
}
[$name, $value] = explode('=', $line, 2);
$name = trim($name);
$value = trim($value);
// 不支持行内注释语法(`FOO=bar # comment` 的 # 会被并入值);如需注释请整行书写。
// 这里仍剥离未加空格直接跟在值后的 "#" 之后内容可能误伤合法值(如 URL 片段),
// 故不做行内剥离,仅在注释中声明限制。
if ($name !== '' && getenv($name) === false) {
putenv($name . '=' . trim($value, "\\\"'"));
}
}
}
require_once(CORE_PATH . '/vendor/autoload.php');
\App\Config::load(CORE_PATH . '/Config.inc.php');