resolveTomlConfig.php
Table of Contents
Functions
- resolveTomlConfig() : array<string|int, mixed>
- Resolves a TOML configuration file and merges it with a default configuration.
Functions
resolveTomlConfig()
Resolves a TOML configuration file and merges it with a default configuration.
resolveTomlConfig(string|null $filePath[, array<string|int, mixed>|null $defaultConfig = [] ][, string|null $defaultPath = null ][, callable|null $init = null ]) : array<string|int, mixed>
This function attempts to load a TOML config file by:
- Ensuring the file path ends with the
.toml
extension. - Resolving relative paths against the current working directory or a given base path.
- Validating the existence of the file and directories.
- Decoding the TOML content to an associative array.
- Deep merging the decoded config with the provided default configuration.
- Optionally applying an initialization callable to the merged configuration.
If $filePath
is null or empty, only the default configuration is returned (possibly processed by $init
).
Parameters
- $filePath : string|null
-
Path to the TOML file. If null or empty, only default config is used.
- $defaultConfig : array<string|int, mixed>|null = []
-
Default configuration array to merge with the TOML file contents.
- $defaultPath : string|null = null
-
Base path used to resolve relative file paths when not absolute.
- $init : callable|null = null
-
Optional callable that takes the merged config array as input and returns a processed config array. Signature:
function(array): array
.
Tags
Return values
array<string|int, mixed> —Merged (and optionally initialized) configuration array.