21 lines
1.0 KiB
PHP
21 lines
1.0 KiB
PHP
<?php
|
|
function lab_config(): array {
|
|
static $config;
|
|
if ($config !== null) return $config;
|
|
$project = dirname(__DIR__, 2);
|
|
$file = getenv('EXOPLASIM_CONFIG') ?: $project . '/config/web.json';
|
|
if (!str_starts_with($file, '/')) $file = $project . '/' . $file;
|
|
$raw = json_decode((string)file_get_contents($file), true, 512, JSON_THROW_ON_ERROR);
|
|
$root = $raw['storage']['root'];
|
|
if (!str_starts_with($root, '/')) $root = $project . '/' . $root;
|
|
$resolve = static fn($path) => str_starts_with($path, '/') ? $path : rtrim($root, '/') . '/' . $path;
|
|
$config = $raw;
|
|
foreach (['database','jobs','runtime','catalog'] as $key) $config[$key] = $resolve($raw['storage'][$key]);
|
|
$config['project_root'] = $project;
|
|
$config['storage_root'] = $root;
|
|
$config['runtime_lock'] = rtrim($root, '/') . '/.runtime.lock';
|
|
$config['storage']['root'] = $root;
|
|
$config['python'] = str_starts_with($raw['python'], '/') ? $raw['python'] : $project . '/' . $raw['python'];
|
|
return $config;
|
|
}
|