Files
UAS_WEBGIS_IhyaUlumuddinHar…/project_final/config/app.php
T
2026-06-13 11:24:58 +07:00

47 lines
1.2 KiB
PHP

<?php
/**
* Application path helpers.
*
* Set APP_BASE_PATH to the subdirectory that serves project_final.
* In this repository's Coolify image the final app runs at /project_final.
*/
function loadEnvFile(): void {
$envFile = __DIR__ . '/../../.env';
if (file_exists($envFile)) {
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos($line, '=') === false || strpos($line, '#') === 0) {
continue;
}
[$key, $value] = explode('=', $line, 2);
$key = trim($key);
$value = trim($value);
if (!getenv($key)) {
putenv("$key=$value");
}
}
}
}
loadEnvFile();
function app_base_path(): string {
$basePath = getenv('APP_BASE_PATH');
if ($basePath === false) {
$basePath = '/project/project_final';
}
$basePath = trim($basePath);
if ($basePath === '' || $basePath === '/') {
return '';
}
return '/' . trim($basePath, '/');
}
function app_url(string $path = ''): string {
$path = '/' . ltrim($path, '/');
return app_base_path() . $path;
}