PHP Class Gush\Config

Configuration is stored per type: system and local, and is always merged into the "all" type which is only used for getting and not setting. Note that the Config class does not check if the provided directories are valid or even exist. This class is only for holding configuration.
Afficher le fichier Open project: gushphp/gush Class Usage Examples

Méthodes publiques

Méthode Description
__construct ( $homedir, array $config = [], $localHome = null, array $localConfig = [] )
get ( string | string[] $keys, string $type = self::CONFIG_ALL, string | integer | float | boolean | array $default = null ) : string | integer | float | boolean | array Returns a config value.
getFirstNotNull ( array $keys, string $type = self::CONFIG_ALL, string | integer | float | boolean | array $default = null ) : string | integer | float | boolean | array Returns the first none-null configuration value.
has ( string $key, string $type = self::CONFIG_ALL ) : boolean Checks whether the config exists.
merge ( array $config, $type ) Merges new config values with the existing ones (overriding).
set ( string $key, string | integer | float | boolean | array $value, string $type ) : Config Merges new config values with the existing ones (overriding).
toArray ( string $type = self::CONFIG_ALL ) : array Get the configuration is as array.

Private Methods

Méthode Description
guardConfigSlot ( string $type ) Guard the configuration slot is valid.

Method Details

__construct() public méthode

public __construct ( $homedir, array $config = [], $localHome = null, array $localConfig = [] )
$config array
$localConfig array

get() public méthode

Returns a config value.
public get ( string | string[] $keys, string $type = self::CONFIG_ALL, string | integer | float | boolean | array $default = null ) : string | integer | float | boolean | array
$keys string | string[] Single level key like 'adapters' or array-path like ['adapters', 'github']
$type string Either Config::CONFIG_SYSTEM Config::CONFIG_LOCAL or Config::CONFIG_ALL
$default string | integer | float | boolean | array Default value to use when no config is found (null)
Résultat string | integer | float | boolean | array

getFirstNotNull() public méthode

Returns the first none-null configuration value.
public getFirstNotNull ( array $keys, string $type = self::CONFIG_ALL, string | integer | float | boolean | array $default = null ) : string | integer | float | boolean | array
$keys array Array of single level keys like "adapters" or property-path "[adapters][github]" to check
$type string Either Config::CONFIG_SYSTEM Config::CONFIG_LOCAL or Config::CONFIG_ALL
$default string | integer | float | boolean | array Default value to use when no config is found (null)
Résultat string | integer | float | boolean | array

has() public méthode

Note. A value with null is considered undefined.
public has ( string $key, string $type = self::CONFIG_ALL ) : boolean
$key string Single level key like "adapters" or property-path "[adapters][github]"
$type string Either Config::CONFIG_SYSTEM Config::CONFIG_LOCAL or Config::CONFIG_ALL
Résultat boolean

merge() public méthode

Merges new config values with the existing ones (overriding).
public merge ( array $config, $type )
$config array

set() public méthode

This can only store a single-key level like "adapters" but not "[adapters][github]".
public set ( string $key, string | integer | float | boolean | array $value, string $type ) : Config
$key string Single level config key
$value string | integer | float | boolean | array Value to store
$type string Either Config::CONFIG_SYSTEM or Config::CONFIG_LOCAL
Résultat Config

toArray() public méthode

Get the configuration is as array.
public toArray ( string $type = self::CONFIG_ALL ) : array
$type string Either Config::CONFIG_SYSTEM Config::CONFIG_LOCAL or Config::CONFIG_ALL
Résultat array