Config
Config
Configuration Class.
class Config implements \ArrayAccess , \Iterator , \CountableImplements: ArrayAccess, Iterator, Countable
The config class loads settings from a configuration file and configures the system ready for the application to run. By default the config file used is application.ini and is stored in the config folder of the application path.
See the documentation for more information
Properties
supportedExtensions
A list of supported configuration file extensions.
private array $supportedExtensions = array (
0 => 'json',
1 => 'ini',
2 => 'php',
)Type: array
overridePaths
private array $overridePathsType: array
instances
private array $instancesType: array
env
Active environment name used when resolving configuration sections.
private string $envType: string
basePath
Base directory prepended to relative configuration source paths.
private string $basePathType: string
sourceFile
public string $sourceFileType: string
global
private array $globalType: array
secureKeys
private array $secureKeysType: array
includes
private array $includesType: array
options
The configuration options for the selected environment.
private array $optionsType: array
Methods
__construct
public __construct(?string $sourceFile, ?string $env, ?array $defaults): voidThe application configuration constructor loads the settings from the configuration file specified in the first parameter. It will use the second parameter as the starting point and is intended to allow different operating environments to be configured from a single configuration file.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sourceFile | string | The absolute path to the config file |
$env | string | The application environment to read settings for. Usually development or production. |
$defaults | array | initial defaut values9 |
setEnvironment
Set the environment for the configuration.
public setEnvironment(string $env): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$env | string | The environment to set |
getEnvironment
Get the current configuration environment.
public getEnvironment(): stringReturns: string
This method returns the environment string (e.g., 'development', 'production', 'staging') currently configured for the configuration instance.
getEnvironments
Retrieve a list of available environments.
public getEnvironments(): arrayReturns: array
This method returns the keys of the global configuration array, which correspond to the available environment names.
setBasePath
Set the base path for the configuration.
public setBasePath(string $path): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string |
getBasePath
Get the base path for the configuration.
public getBasePath(): stringReturns: string
setOverridePaths
Set the source file for the configuration.
public setOverridePaths(array $paths): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$paths | array | The paths to search for the configuration file overrides |
reload
Reloads the configuration from the source file.
public reload(): boolReturns: bool
This method clears the current configuration options, includes, and secure keys, then attempts to reload the configuration from the original source file.
loadFromFile
Loads a configuration file and returns the configuration options.
public loadFromFile(string $source, ?array $defaults, bool $force): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$source | string | the name of the configuration file to load |
$defaults | array | (optional) The default configuration options |
$force | bool | (optional) Whether to force reloading the configuration even if it has been loaded before |
loadFromArray
Loads the configuration options from an array.
public loadFromArray(array $options, ?array $defaults): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | array | The configuration options to load |
$defaults | array | (optional) The default configuration options |
getEnvConfig
Retrieves the environment configuration array.
public getEnvConfig(?string $env): arrayReturns: array
This method returns the configuration array for the specified environment. If no environment is specified, it uses the default environment set in the application.
Parameters
| Parameter | Type | Description |
|---|---|---|
$env | string | The environment for which to retrieve the configuration. Defaults to null. |
toString
Converts the configuration object to a string representation.
public toString(): stringReturns: string
toSecureArray
Converts the configuration object to a secure array by removing the secure keys.
public toSecureArray(): arrayReturns: array
get
public get(string $key): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string |
offsetExists
Checks if the specified option exists in the configuration.
public offsetExists(mixed $offset): boolReturns: bool
Implements the ArrayAccess interface method to determine if a given offset exists within the internal options array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | the option key to check for existence |
offsetGet
Retrieves the value associated with the specified offset from the options array.
public offsetGet(mixed $offset): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | the offset to retrieve |
offsetSet
Sets the value at the specified offset in the options array.
public offsetSet(mixed $offset, mixed $value): voidReturns: void
This method is typically used to implement the ArrayAccess interface, allowing the object to be accessed as an array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | the offset to assign the value to |
$value | mixed | the value to set at the specified offset |
offsetUnset
Unsets the option at the specified offset.
public offsetUnset(mixed $offset): voidReturns: void
This method removes the value associated with the given offset from the options array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | the offset to unset |
toArray
Converts the configuration object to an array.
public toArray(): arrayReturns: array
current
Returns the current element from the options array.
public current(): mixedReturns: mixed
next
Advances the internal pointer of the options array to the next element.
public next(): voidReturns: void
key
Retrieves the key of the current element in the options array.
public key(): mixedReturns: mixed
valid
Checks if the current options array has a valid key.
public valid(): boolReturns: bool
rewind
Rewinds the internal pointer of the options array to the first element.
public rewind(): voidReturns: void
This method is typically used when implementing the Iterator interface, allowing iteration to start from the beginning of the options array.
count
Returns the number of elements in the options array.
public count(): intReturns: int
extend
Extends the configuration options with the given configuration array.
public extend(array $config): voidReturns: void
This method merges the given configuration array with the existing configuration options.
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | array | the configuration array to extend the existing configuration options |
loadSourceFile
Loads the configuration file from the given source.
private loadSourceFile(string $source, bool $force): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$source | string | the path to the configuration file |
$force | bool | (optional) Whether to force reloading the configuration even if it has been loaded before |
loadConfigOptions
Loads the configuration options into the provided Map object based on the given options array and environment.
private loadConfigOptions(array $config, array $globalOptions, ?string $env, bool $force): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | array | the config to store the configuration options |
$globalOptions | array | the global options to load the configuration from |
$env | string | The environment to load the configuration for. If null, the default environment will be used. |
$force | bool |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000