/** * config factory * * @param string registry index * @return mixed registry entry * @throws Exception if no entry is registerd for given index */ public static function get($index) { // check if config is already loaded if (isset(self::$data[$index])) { return self::$data[$index]; } // try magic autoloading switch ($index) { case 'cfg': require 'configs/base.php'; // set defaults if (empty($cfg['layout'])) { $cfg['layout'] = 'set1'; } $cfg['urlImg'] = $cfg['image_baseurl']; $cfg['urlIcons'] = $cfg['urlImg'] . $cfg['layout'] . '/ic/'; $cfg['urlGfx'] = $cfg['urlImg'] . $cfg['layout'] . '/gfx/'; $cfg['urlCSS'] = $cfg['urlImg'] . $cfg['layout'] . '/css/'; self::setConfig('cfg', $cfg); break; case 'lvs': require 'configs/LVSConfig.php'; self::setConfig('lvs', $cfg); break; default: $includePath = get_include_path(); $includePath = explode(':', $includePath); foreach ($includePath as $path) { if (substr($path, -1, 1) != DIRECTORY_SEPARATOR) { $path .= DIRECTORY_SEPARATOR; } $file = $path . 'configs' . DIRECTORY_SEPARATOR . $index . '.php'; if (is_readable($file)) { // prepare regEx if (null === self::$cacheConfigRegEx) { self::$cacheConfigRegEx = '~^(' . implode('|', self::$cacheConfigs) . ')~'; } // check if config is cachable if (!preg_match(self::$cacheConfigRegEx, $index)) { require $file; if (isset($cfg)) { self::setConfig($index, $cfg); } else { error_log('cant´t find variable $cfg in configfile ' . $file); } break 2; } // prepare and cache config $cacheFile = $path . self::$cacheDir . Localizer::getLanguage() . DIRECTORY_SEPARATOR . $index . '.php'; // load cached config if (!KWICK_DEV && is_readable($cacheFile)) { require $cacheFile; self::setConfig($index, $cfg); break 2; } // process $data = file_get_contents($file); Preprocessor::process($data, $index, Translatr::TYPE_CONFIG, $path); // save and load cache file try { File::put($cacheFile, $data); } catch (Exception $e) { SC_Log::get()->exception($e); } require $cacheFile; self::setConfig($index, $cfg); break 2; } } throw new Exception('No entry is registered and autoloading has failed for key "' . $index . '"'); } if (isset(self::$data[$index])) { return self::$data[$index]; } else { return false; } }