48 lines
1.7 KiB
PHP
48 lines
1.7 KiB
PHP
<?php
|
|
// Mobile API config. Values come from the environment (same .env as Laravel).
|
|
|
|
// Real environment variables win; anything missing is filled from the project .env
|
|
// (docker-compose only exports DB_*, while MAIL_* live in the .env file).
|
|
(static function (): void {
|
|
// config.php is required by several endpoints; parse .env only once per request.
|
|
if (defined('CASADOC_ENV_LOADED')) {
|
|
return;
|
|
}
|
|
define('CASADOC_ENV_LOADED', true);
|
|
$envFile = __DIR__ . '/../../../.env';
|
|
if (!is_readable($envFile)) {
|
|
return;
|
|
}
|
|
foreach (file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
|
|
$line = trim($line);
|
|
if ($line === '' || $line[0] === '#' || !str_contains($line, '=')) {
|
|
continue;
|
|
}
|
|
[$key, $value] = explode('=', $line, 2);
|
|
$key = trim($key);
|
|
$value = trim(trim(trim($value), '"'), "'");
|
|
if ($key !== '' && getenv($key) === false) {
|
|
putenv("$key=$value");
|
|
}
|
|
}
|
|
})();
|
|
|
|
return [
|
|
'db_host' => getenv('DB_HOST') ?: '127.0.0.1',
|
|
'db_port' => getenv('DB_PORT') ?: '3306',
|
|
'db_name' => getenv('DB_DATABASE') ?: 'casadocdb',
|
|
'db_user' => getenv('DB_USERNAME') ?: 'root',
|
|
'db_pass' => getenv('DB_PASSWORD') ?: '',
|
|
|
|
'token_ttl_days' => 30,
|
|
|
|
'homedocs_dir' => __DIR__ . '/../homedocuments',
|
|
'persondocs_dir' => __DIR__ . '/../persondocuments',
|
|
'mainphoto_dir' => __DIR__ . '/../mainphoto',
|
|
'avatars_dir' => __DIR__ . '/../../upload/users',
|
|
|
|
'app_url' => rtrim(getenv('APP_URL') ?: '', '/'),
|
|
|
|
'assets_base_url' => rtrim(getenv('ASSETS_BASE_URL') ?: '', '/'),
|
|
];
|