| 1 |
<?php |
| 2 |
namespace FileBird\Classes; |
| 3 |
|
| 4 |
class Config { |
| 5 |
private static $loaded_configs = array(); |
| 6 |
|
| 7 |
/** |
| 8 |
* Set config |
| 9 |
* |
| 10 |
* Eg: Config::setConfig('PostType', $data); |
| 11 |
* or: Config::setConfig('PostType.name', 'foo'); |
| 12 |
*/ |
| 13 |
|
| 14 |
public static function setConfig( $name, $data ) { |
| 15 |
$ex = explode( '.', $name ); |
| 16 |
if ( count( $ex ) == 1 ) { |
| 17 |
self::$loaded_configs[ $name ] = $data; |
| 18 |
} elseif ( count( $ex ) == 2 ) { |
| 19 |
if ( ! isset( self::$loaded_configs[ $ex[0] ] ) ) { |
| 20 |
self::$loaded_configs[ $ex[0] ] = array(); |
| 21 |
} |
| 22 |
self::$loaded_configs[ $ex[0] ][ $ex[1] ] = $data; |
| 23 |
} |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Get loaded config |
| 29 |
* |
| 30 |
* Eg: Config::getConfig('PostType.name'); |
| 31 |
*/ |
| 32 |
|
| 33 |
public static function getConfig( $name ) { |
| 34 |
$ex = explode( '.', $name ); |
| 35 |
if ( count( $ex ) == 2 ) { |
| 36 |
if ( isset( self::$loaded_configs[ $ex[0] ] ) && isset( self::$loaded_configs[ $ex[0] ][ $ex[1] ] ) ) { |
| 37 |
return self::$loaded_configs[ $ex[0] ][ $ex[1] ]; |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
|