Core\Config::get
Core\Config::get(string $name): ?stringCore\Config::get( string $name, ): ?string
Gives the value of one setting for this request.
The name is the dotted name a configuration file uses, such as log.level. A limit also has a short name: memory, cpu_time, wall_time, max_tasks, max_output and max_regex_steps each name one entry of the [limits] group. The value is always text, written the way the configuration file writes it, so a number comes back as "64" and a yes-or-no setting as "true". A setting your program changed with Core\Config::set comes back with the new value.
A setting the configuration file does not write gives its built-in default. memory gives "128M", and max_regex_steps gives "1000000".
Good to know: the result is null for a setting that has no default, such as wall_time. It is also null for a name that has a group of settings or a list, because neither of those is one value.
Parameters
$namestringThe dotted name of the setting, such aslog.level. A limit name alone is the setting of that name in[limits]. The limit names arememory,cpu_time,wall_time,max_tasks,max_outputandmax_regex_steps.
Return value
Returns ?string. The value as text, written the way the configuration file writes it, such as 128M or 30s. The result is null for a setting with no default, such as wall_time. It is also null for a name that has a group of settings or a list. A secret setting, such as db.main.password or http.csrf_key, gives a ?secret string. Your program cannot print it or write it to a log.
Errors
LogicErrorThe name is a secret setting, and the call does not write it as a string literal. Write the name in the call, such asCore\Config::get('db.main.password').
Examples
Read one setting
<?nvs// Shows how to read one setting. `Core\Config::get` returns the value as text.// A setting the configuration file does not write gives its built-in default.
// Nothing sets this limit here, so this prints the default, 1000000.echo Core\Config::get('max_regex_steps') ?? 'no limit', "\n";
// `wall_time` has no default, so the result is `null`. This prints no limit.echo Core\Config::get('wall_time') ?? 'no limit', "\n";1000000no limitA setting is text
<?nvs// Shows that every setting is text. `Core\Config::get` returns what the// configuration file wrote, so a program that needs a number converts it.
// The server usually writes this in the configuration file. This example sets// it, so that it prints the same value everywhere.Core\Config::set('max_tasks', '16');
string $written = Core\Config::get('max_tasks') ?? '1';
// This prints 16 and then 17. `as ?int` converts text to a whole number, and// the result is `null` for text that is not one.echo $written, "\n";echo (($written as ?int) ?? 1) + 1, "\n";1617Read the limits a job runs under
<?nvs// Shows how a program reads the limits it runs under before it starts a job.// `Core\Config::get` returns one setting, so a program asks for the two or// three names it needs.
// The server usually writes these in the configuration file. This example sets// them, so that it prints the same values everywhere.Core\Config::set('max_tasks', '8');Core\Config::set('memory', '256M');
// A limit can be written with its short name here, or with the full name the// configuration file uses, `limits.max_tasks`.string $tasks = Core\Config::get('max_tasks') ?? '1';string $memory = Core\Config::get('limits.memory') ?? 'unknown';
// This prints: 8 jobs at a time, inside 256M.echo $tasks, ' jobs at a time, inside ', $memory, "\n";8 jobs at a time, inside 256M