bar [section1] => Array ( [foo1] => bar1 ) ) */ class Config { public static function get($key, $section = null) { static $_main_config; if ($_main_config === null) { $_main_config = self::getConfFile(); } if ($key == 'get-all-data') { return $_main_config; } $cur_conf = $_main_config; if ($section !== null) { $cur_conf = V::get($section, null, $_main_config); } return V::get($key, null, $cur_conf); } public static function getData() { return self::get('get-all-data'); } /** * Search for zasob config ini file. * Config file name must contain zasob_{$ID} for example: * .cnf--zasob_{$ID}.ini.php - config file for zasob $ZASOB_ID * .cnf--zasob_{$ID}-{$host}.ini.php - config file for zasob $ZASOB_ID on host */ public static function getZasobConf($zasob_id) { return self::getConfFile("zasob_{$zasob_id}"); } /** * Search for zasob config ini file. */ public static function getColumnConf($col) { return self::getConfFile("column_init_{$col}"); } /** * Search for config ini file. * TODO: $conf_file == '' - main config file */ public static function getConfFile($conf_file = '') { static $_cnf; if (!is_array($_cnf)) $_cnf = array(); if (array_key_exists($conf_file, $_cnf)) { return $_cnf[$conf_file]; } $_cnf[$conf_file] = null; $cnf = null; $file_prefix = '.cnf'; if ($conf_file != '') $file_prefix .= '--'.$conf_file; $file_suffix = '.ini.php'; $search_for_files = array();// kolejka includowania plikow $host = $_SERVER['SERVER_NAME']; $search_for_files[] = APP_PATH_CONFIG . DS . $file_prefix . '-' . $host . $file_suffix; // dziedziczenie - subdomain np. www.biall.com.pl i www2.biall.com.pl -> biall.com.pl $host_subdomain_exp = explode('.', $host); $host_subdomain = reset($host_subdomain_exp); $host_parent = substr($host, strlen($host_subdomain . '.')); $search_for_files[] = APP_PATH_CONFIG . DS . $file_prefix . '-' . $host_parent . $file_suffix; $search_for_files[] = APP_PATH_CONFIG . DS . $file_prefix . $file_suffix; foreach ($search_for_files as $f) { if (1 == V::get('DBG_CNF', '', $_GET)) { echo "f(" . end(explode('/',$f)) . ")=(" . file_exists($f) . ")"; } if (file_exists($f)) { Lib::loadClass('Core_Config_INI'); $cnf = new Core_Config_INI($f); $_cnf[$conf_file] = $cnf->getData(); break; } } return $_cnf[$conf_file]; } }