Reading and changing it from a program: Core\Config
Core\Config reads the configuration and changes some settings for the current request.
A setting's name is its path in the file with dots, such as limits.hard.memory. A limit also has a short name: memory is limits.memory.
get returns the value as a string, or the built-in default. The result is null for a setting with no default. It is also null for a name whose value is a table or a list.
set changes a value for the current request only. Other requests and spawned scripts do not see it. set never throws. It returns false and changes nothing when the change is not allowed. restore removes the change for one name. all returns every value, sorted by name.
set changes only the settings in the list on the page of Core\Config::set. Only the file sets every other setting. The compiler checks a name written as text in the call. If set may never change that setting, the program does not compile.
Good to know: a limit's ceiling is the highest value a program may set. It is the limit's value in [limits.hard], or else its value in [limits].
Examples
The examples below run with this configuration file.
# A request starts with 128M of memory. A program may raise it up to 512M, and no higher.[limits]memory = "128M"
[limits.hard]memory = "512M"More memory for one large export
<?nvs// Shows a program that raises its memory limit for one large export, and then sets it back.
// This prints `128M`, the value from `nvs.toml`.echo Core\Config::get('memory'), "\n";
// The export needs more memory. `set` returns `true`, and the limit is now `384M`.echo Core\Config::set('memory', '384M') ? 'true' : 'false', "\n";echo Core\Config::get('memory'), "\n";
// `1G` is above the highest limit in `nvs.toml`. `set` returns `false` and the limit stays `384M`.echo Core\Config::set('memory', '1G') ? 'true' : 'false', "\n";echo Core\Config::get('memory'), "\n";
// The export builds 200000 lines of 11 characters each. This prints `2200000`.array<string> $lines = [];uint $i = 0;while ($i < 200000) { $lines[] = "order line\n"; $i = $i + 1;}echo Core\Str::length(Core\Str::join($lines, '')), "\n";
// `restore` sets the limit back to the value from `nvs.toml`. This prints `128M`.Core\Config::restore('memory');echo Core\Config::get('memory'), "\n";128Mtrue384Mfalse384M2200000128MChangelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
