Config
in package
Config handler
Loads INI files, caches the retrieved values
Table of Contents
- $cached : mixed
- $config : mixed
- __construct() : mixed
- get() : mixed
- getArray() : array<string|int, mixed>
- Returns with an array from the config
- getCommaSeparatedValues() : array<string|int, mixed>
- Returns with an array from a comma separated string config value
- getFullPath() : string
- Replaces the ~ symbol with the `app.root_path` config value
- isCached() : bool
- Returns true if the config value is cached
- load() : mixed
- Loads an INI file and merges with current config
- cacheAndReturn() : mixed
- Caches a value if the `$useCache` is true and returns with it
- getArrayItemValue() : string
- Trims and replaces variables to environment variable values in a string
- replaceEnvValue() : mixed|null
- Replaces the {{name}} formatted variables in a string with environment variable values
Properties
$cached
private
mixed
$cached
= []
$config
private
mixed
$config
= []
Methods
__construct()
public
__construct() : mixed
Return values
mixed —get()
public
get(mixed $name[, mixed $default = null ][, mixed $useCache = true ]) : mixed
Parameters
- $name : mixed
- $default : mixed = null
- $useCache : mixed = true
Return values
mixed —getArray()
Returns with an array from the config
public
getArray( $prefix[, array<string|int, mixed> $default = [] ][, bool $useCache = true ]) : array<string|int, mixed>
For example: with the following config:
persons.0.name = "name1" persons.0.age = "32" persons.1.name = "name2" persons.1.age = "42"
the result will be for $config->getArray('persons')
:
[ "0" => [ "name" => "name1", "age" => "32" ], "1" => [ "name" => "name2", "age" => "42" ] ]
Parameters
Return values
array<string|int, mixed> —getCommaSeparatedValues()
Returns with an array from a comma separated string config value
public
getCommaSeparatedValues(string $name[, bool $useCache = true ]) : array<string|int, mixed>
For example: "1, 2, 3" will result in ['1', '2', '3']
Parameters
- $name : string
-
The config name
- $useCache : bool = true
-
Use the cache for retrieving the value?
Return values
array<string|int, mixed> —The result in array
getFullPath()
Replaces the ~ symbol with the `app.root_path` config value
public
getFullPath(string $path) : string
Parameters
- $path : string
Return values
string —isCached()
Returns true if the config value is cached
public
isCached(string $name) : bool
Parameters
- $name : string
-
Name of the config
Return values
bool —Is the config value cached?
load()
Loads an INI file and merges with current config
public
load(string $path) : mixed
It does NOT process sections! The "true", "false", "no", "yes", "on", "off" values will be replaced with true and false values.
Parameters
- $path : string
-
The path of the INI file
Return values
mixed —cacheAndReturn()
Caches a value if the `$useCache` is true and returns with it
protected
cacheAndReturn(string|null $name, string|array<string|int, mixed>|null $value[, bool $useCache = true ]) : mixed
Parameters
- $name : string|null
-
The config name
- $value : string|array<string|int, mixed>|null
-
The value
- $useCache : bool = true
-
Use the cache?
Return values
mixed —getArrayItemValue()
Trims and replaces variables to environment variable values in a string
protected
getArrayItemValue(string $value) : string
Parameters
- $value : string
-
The value for trim and replace
Return values
string —The trimmed and replaced value
replaceEnvValue()
Replaces the {{name}} formatted variables in a string with environment variable values
protected
replaceEnvValue(string|null $value) : mixed|null
Parameters
- $value : string|null
-
The value
Return values
mixed|null —The replaced string