Config

Reference for the Config module: register and read typed, per-module configuration values. Modules declare the values they need; the application provides them up front; a security check confirms nothing required is missing before a request is served.

This page is a pure reference. For how a site provides its configuration, see the guide: Configuration.

Classes
  • Config - register and read typed, per-module configuration values.

Config

Register the configuration a module needs, read the values the application provided, and verify that everything required is present. Values are keyed by module and value name, and are typed with the constants below.

Constants

ConstantValueDescription
Config::TYPE_STRING'string'A string value.
Config::TYPE_INTEGER'integer'A whole number.
Config::TYPE_FLOAT'float'A decimal number.
Config::TYPE_BOOLEAN'boolean'A true or false value.
Config::TYPE_CALLABLE'callable'A callable value.
Config::TYPE_STRING_ARRAY'string_array'A list of strings.

Call

Config::Call(string $moduleName, string $valueName, mixed ...$args): mixed

Get a config value that is a callable and invoke it with the given arguments.

NameTypeDescription
$moduleNamestringThe module that registered the value.
$valueNamestringThe config value name; must hold a callable.
...$argsmixedThe arguments passed to the callback.

Returns mixed The value returned by the callback.

Get

Config::Get(string $moduleName, string $valueName): mixed

Get a registered config value: the provided value, or the optional default. Throws when a required value was not provided.

NameTypeDescription
$moduleNamestringThe module that registered the value.
$valueNamestringThe config value name.

Returns mixed The configuration value.

GetModules

Config::GetModules(): array

The names of all modules that have registered config, sorted.

Returns array A list of module names.

GetModuleValues

Config::GetModuleValues(string $moduleName): array

Every registered config value for a module, keyed by value name.

NameTypeDescription
$moduleNamestringThe module to read values for.

Returns array A map of value name to value.

GetOptional

Config::GetOptional(string $moduleName, string $valueName, mixed $defaultValue): mixed

Get a provided config value, or the given default when it was not provided.

NameTypeDescription
$moduleNamestringThe module that registered the value.
$valueNamestringThe config value name.
$defaultValuemixedThe value to return when none was provided.

Returns mixed The configuration value, or the default.

GetSchema

Config::GetSchema(?string $moduleName = null): array

The registered config schema entries, optionally filtered to one module.

NameTypeDescription
$moduleName?stringA module name to filter by, or null for every entry.

Returns array The schema entries.

Optional

Config::Optional(string $moduleName, string $valueName, string $valueType, mixed $defaultValue): void

Register an optional config value with a default. Idempotent when re-registered with the same type.

NameTypeDescription
$moduleNamestringThe module registering the value.
$valueNamestringThe config value name.
$valueTypestringOne of the Config type constants.
$defaultValuemixedThe value used when none is provided.

Returns void

Provide

Config::Provide(string $moduleName, array $configArray): void

Supply config values for a module, as a map of value name to value. Called by the application before modules load; types are checked later by SecurityCheck.

NameTypeDescription
$moduleNamestringThe module the values belong to.
$configArrayarrayA map of value name to value; nested arrays are not allowed.

Returns void

Required

Config::Required(string $moduleName, string $valueName, string $valueType): void

Register a required config value. Idempotent when re-registered with the same type.

NameTypeDescription
$moduleNamestringThe module registering the value.
$valueNamestringThe config value name.
$valueTypestringOne of the Config type constants.

Returns void

SecurityCheck

Config::SecurityCheck(): void

Verify every required config value was provided and every provided value matches its registered type. Run after all modules load; throws listing anything missing.

Returns void