123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php namespace System;
- class Config {
-
- private static $items = array();
-
- public static function get($key)
- {
-
-
-
- list($file, $key) = static::parse($key);
-
-
-
- static::load($file);
- return (array_key_exists($key, static::$items[$file])) ? static::$items[$file][$key] : null;
- }
-
- public static function set($key, $value)
- {
-
-
-
- list($file, $key) = static::parse($key);
-
-
-
- static::load($file);
- static::$items[$file][$key] = $value;
- }
-
- private static function parse($key)
- {
- $segments = explode('.', $key);
- if (count($segments) < 2)
- {
- throw new \Exception("Invalid configuration key [$key].");
- }
-
-
-
-
-
- return array($segments[0], implode('.', array_slice($segments, 1)));
- }
-
- public static function load($file)
- {
-
-
-
- if (array_key_exists($file, static::$items))
- {
- return;
- }
- if ( ! file_exists($path = APP_PATH.'config/'.$file.EXT))
- {
- throw new \Exception("Configuration file [$file] does not exist.");
- }
- static::$items[$file] = require $path;
- }
- }
|