Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Config {
- private static $store = array();
- public static function get($index, $default = null) {
- $index = explode('.', $index);
- if($index[0] == 'app'){
- if(!isset(self::$store['app'][$index[1]])){
- if(file_exists(DIR_APP_CONFIG . $index[1] . EXT)){
- self::$store['app'][$index[1]] = include_once DIR_APP_CONFIG . $index[1] . EXT;
- } else {
- throw new Edge_Exception('No such config file :file in :in', array(":file" => $index[1] . EXT, ":in" => DIR_APP_CONFIG));
- }
- }
- $cfg = self::$store['app'][$index[1]];
- }
- try {
- $return = self::getValue($index, self::$store);
- } catch (Edge_Exception $e) {
- if (!is_null($default)) {
- $return = $default;
- } else {
- throw $e;
- }
- }
- return $return;
- }
- protected static function getValue($index, $value) {
- if (is_array($index) and count($index)) {
- $current_index = array_shift($index);
- }
- if (is_array($index) and count($index) and isset($value[$current_index]) and is_array($value[$current_index]) and count($value[$current_index])) {
- return self::getValue($index, $value[$current_index]);
- } elseif (isset($value[$current_index])) {
- return $value[$current_index];
- } else {
- throw new Edge_Exception("Attempt to access missing configuration variable: :current_index",
- array(":current_index" => $current_index)
- );
- }
- }
- }
- //End Config
Advertisement
Add Comment
Please, Sign In to add comment