Skip to content

Core\Config

Reads the settings of nvs.toml for the current request. You can change some settings for this request only, and reset them again.

Core\Config reads and moves the configuration in force for the current request. Every value crosses as a string, spelled as nvs.toml would spell it ("512M", "30s"); a directive is named with dots (log.level), and a bare limit name — memory, cpu_time, wall_time, max_tasks, max_output — is the [limits] entry. set changes a directive for this request alone and answers false, leaving the value in place, for anything it may not do: a directive only the file may set, an unknown name, a value of the wrong shape, or a value above the [limits.hard] ceiling the operator kept. When [limits.hard] does not set a limit, its ceiling is the value the request started with, so a program cannot raise it. A program you start from the command line is the one exception: with no [limits.hard] memory, it may raise memory to any value. restore puts the file's value back, or the built-in default when the file does not write the key. get and all give the built-in default of every key the file does not write, such as 128M for memory. A key with no default, such as wall_time, is null.

[limits]
memory = "256M"
[limits.hard]
memory = "512M"
<?nvs
echo 'memory=', Core\Config::get('memory') ?? 'unset', "\n";
echo Core\Config::set('memory', '512M') ? 'raised to the ceiling' : 'refused', "\n";
echo Core\Config::set('memory', '1G') ? 'raised past it' : 'refused past the ceiling', "\n";
echo 'now=', Core\Config::get('limits.memory') ?? 'unset', "\n";
Core\Config::restore('memory');
echo 'restored=', Core\Config::get('memory') ?? 'unset', "\n";
// A name written directly in `set` that a program may not change does not compile.
// This name is in a variable, so the call runs and returns `false`.
string $unknown = 'no.such.directive';
echo Core\Config::set($unknown, '1') ? 'set' : 'unknown name refused', "\n";
Output
memory=256M
raised to the ceiling
refused past the ceiling
now=512M
restored=256M
unknown name refused

Members

6 members.

MemberSignature
getget(string $name): ?string
setset(string $name, string $value): bool
restorerestore(string $name): void
allall(): array<string>
settingsetting(string $name): ?string|int|float|bool|array<mixed>
secretsecret(string $name): ?secret string