Core\Config::all
Core\Config::all(): array<string>Gives every setting in force for this request, as one array.
The keys are the dotted names a configuration file uses, such as limits.memory or log.level, and they are sorted by name. Every value is text, written the way the configuration file writes it. A setting the configuration file does not write is in the array with its built-in default. A setting your program changed with Core\Config::set is in the array with the new value. A name that holds a group of settings is not an entry of its own, and a name that holds a list is not in the array at all.
Good to know: the array is a copy. Changing it changes no setting. It also holds passwords that were read from a secret file, so do not write the whole array into a log.
Return value
Returns array<string>. An array<string, string> sorted by name, with one entry per value. A name that has a group of settings gives one entry for each setting in it. A name that has a list gives no entry. A secret setting, such as db.main.password or http.csrf_key, has the value <secret>. get returns the real value.
Examples
Read the settings in force
<?nvs// Shows how to read the settings in force for this request. `Core\Config::all`// returns all of them as one array, with the dotted names as keys.
// A job that takes longer than a web request gives itself more time and memory.Core\Config::set('wall_time', '45s');Core\Config::set('memory', '384M');
array<string> $settings = Core\Config::all();
// This prints 45s and then 384M. `set` takes the short name `memory`, and the// array uses the full name `limits.memory`.echo $settings['limits.wall_time'], "\n";echo $settings['limits.memory'], "\n";45s384MSee what your program changed
<?nvs// Shows which settings a program has changed. `Core\Config::all` returns the// settings in force now, so a copy of it taken before a change can be compared// with the settings after the change.
array<string> $before = Core\Config::all();
Core\Config::set('max_tasks', '4');Core\Config::set('log.level', 'warning');
// The loop prints the names that are new or have a new value. Here that is// limits.max_tasks and log.level.foreach (Core\Config::all() as string $name => string $value) { if (!Core\Arr::hasKey($before, $name) || $before[$name] != $value) { echo $name, ' = ', $value, "\n"; }}limits.max_tasks = 4log.level = warningCheck the settings a job asked for
<?nvs// Shows how to check that the settings a program asked for are really in force.// `Core\Config::set` returns `false` when a change is not allowed, and// `Core\Config::all` says what is in force after every change.
// A worker picks the settings for one long job.array<string> $wanted = [ 'limits.memory' => '384M', 'limits.wall_time' => '120s', 'limits.max_tasks' => '8',];
foreach ($wanted as string $name => string $value) { Core\Config::set($name, $value);}
array<string> $inForce = Core\Config::all();
// This prints one line per setting. A setting the server does not allow this// program to change is reported as not changed.foreach ($wanted as string $name => string $value) { if (Core\Arr::hasKey($inForce, $name) && $inForce[$name] == $value) { echo $name, ' is ', $value, "\n"; } else { echo $name, ' was not changed', "\n"; }}limits.memory is 384Mlimits.wall_time is 120slimits.max_tasks is 8