Config class.
Protected constructor since this is a static class.
NULL
protected function __construct()
{
// Nothing here
}
Returns config value or entire config array from a file.
| Type | Description |
|---|---|
| string | Config key |
| mixed | (optional) Default value to return if config value doesn't exist |
mixed
public static function get($key, $default = null)
{
$keys = explode('.', $key, 2);
if(!isset(static::$config[$keys[0]]))
{
$path = Mako::path('config', $keys[0]);
if(file_exists($path) === false)
{
throw new RuntimeException(vsprintf("%s(): The '%s' config file does not exist.", array(__METHOD__, $keys[0])));
}
static::$config[$keys[0]] = include($path);
}
if(!isset($keys[1]))
{
return static::$config[$keys[0]];
}
else
{
return Arr::get(static::$config[$keys[0]], $keys[1], $default);
}
}
Sets a config value.
| Type | Description |
|---|---|
| string | Config key |
| mixed | Config value |
NULL
public static function set($key, $value)
{
$config = strtok($key, '.');
if(!isset(static::$config[$config]))
{
static::get($config);
}
Arr::set(static::$config, $key, $value);
}
Deletes a value from the configuration.
| Type | Description |
|---|---|
| string | Config key |
boolean
public static function delete($key)
{
return Arr::delete(static::$config, $key);
}