初始化
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// 加载 .env 文件中的环境变量
|
||||
$envFile = __DIR__ . '/../.env';
|
||||
if (file_exists($envFile) && is_readable($envFile)) {
|
||||
$lines = @file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
if ($lines !== false) {
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '' || $line[0] === '#') continue;
|
||||
if (strpos($line, '=') !== false) {
|
||||
list($key, $value) = explode('=', $line, 2);
|
||||
$key = trim($key);
|
||||
$value = trim($value);
|
||||
// 去除引号包裹
|
||||
if ((str_starts_with($value, '"') && str_ends_with($value, '"')) ||
|
||||
(str_starts_with($value, "'") && str_ends_with($value, "'"))) {
|
||||
$value = substr($value, 1, -1);
|
||||
}
|
||||
if (!array_key_exists($key, $_ENV)) {
|
||||
$_ENV[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$config['db']['host'] = $_ENV['DB_HOST'] ?? 'localhost';
|
||||
$config['db']['username'] = $_ENV['DB_USER'] ?? 'root';
|
||||
$config['db']['password'] = $_ENV['DB_PASS'] ?? '';
|
||||
$config['db']['dbname'] = $_ENV['DB_NAME'] ?? 'mes2';
|
||||
$config['db']['company'] = $_ENV['DB_COMPANY'] ?? 'Default Company';
|
||||
$config['defaultAction'] = 'index';
|
||||
return $config;
|
||||
Reference in New Issue
Block a user