Index: trunk/core/kernel/utility/unit_config_reader.php =================================================================== diff -u -r4765 -r4766 --- trunk/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 4765) +++ trunk/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 4766) @@ -26,135 +26,6 @@ parent::Init($prefix,$special); } - /** - * Checks if config file is allowed for includion (if module of config is installed) - * - * @param string $config_path relative path from in-portal directory - */ - function configAllowed($config_path) - { - $module_found = false; - if (!$this->Application->ModuleInfo) return false; - - foreach($this->Application->ModuleInfo as $module_name => $module_info) - { - $module_path = '/'.$module_info['Path']; - if (preg_match('/^'.preg_quote($module_path, '/').'/', $config_path)) { - // if (substr($config_path, 0, strlen($module_path)) == $module_path) { - // config file path starts with module folder path - $module_found = true; - break; - } - } - return $module_found; - } - - /** - * Returns true if config exists and is allowed for reading - * - * @param string $prefix - * @return bool - */ - function prefixRegistred($prefix) - { - return isset($this->configData[$prefix]) ? true : false; - } - - /** - * Read configs from all directories - * on path specified - * - * @param string $folderPath - * @access public - */ - function processFolder($folderPath, $cached) - { - $fh = opendir($folderPath); - while (($sub_folder = readdir($fh))) { - $full_path = $folderPath.'/'.$sub_folder; - if( $this->isDir($full_path) && file_exists($this->getConfigName($full_path)) ) - { - if (filemtime($full_path) > $cached) { - $this->CacheExpired = true; - - $file = $this->getConfigName($full_path); - if ( $this->Application->isDebugMode() && constOn('DBG_PROFILE_INCLUDES') ) - { - - if ( in_array($file, get_required_files()) ) return; - global $debugger; - /*$debugger->IncludeLevel++; - $before_time = getmicrotime(); - $before_mem = memory_get_usage();*/ - k4_include_once(FULL_PATH.$file); - /*$used_time = getmicrotime() - $before_time; - $used_mem = memory_get_usage() - $before_mem; - $debugger->IncludeLevel--; - $debugger->IncludesData['file'][] = str_replace(FULL_PATH, '', $file); - $debugger->IncludesData['mem'][] = $used_mem; - $debugger->IncludesData['time'][] = $used_time; - $debugger->IncludesData['level'][] = -1;*/ - } - else { - include_once($file); - } - - if ( !isset($config) || !$config ) continue; - $prefix = $config['Prefix']; - $config['BasePath'] = $full_path; - $this->configData[$prefix] = $config; - } - } - } - } - - function postProcessConfig($prefix, $config_key, $dst_prefix_var) - { - $main_config =& $this->configData[$prefix]; - $sub_configs = getArrayValue($main_config, $config_key); - if (!$sub_configs) { - return false; - } - unset($main_config[$config_key]); - - foreach ($sub_configs as $sub_prefix => $sub_config) { - if ($config_key == 'AggregateConfigs' && !isset($this->configData[$sub_prefix])) { - $this->loadConfig($sub_prefix); - } - $sub_config['Prefix'] = $sub_prefix; - $this->configData[$sub_prefix] = array_merge_recursive2($this->configData[$$dst_prefix_var], $sub_config); - - // when merging empty array to non-empty results non-empty array, but empty is required - foreach ($sub_config as $sub_key => $sub_value) { - if (!$sub_value) { - unset($this->configData[$sub_prefix][$sub_key]); - } - } - if ($config_key == 'Clones') { - $this->prefixFiles[$sub_prefix] = $this->prefixFiles[$prefix]; - } - - $this->postProcessConfig($sub_prefix, $config_key, $dst_prefix_var); - if ($config_key == 'AggregateConfigs') { - $this->postProcessConfig($sub_prefix, 'Clones', 'prefix'); - } - } - - if (!$prefix) { - // configs, that used only for cloning & not used ifself - unset($this->configData[$prefix]); - } - } - - function ParseConfigs() - { - $this->parseConfig('formatters'); // !TEMPORARY!, until config dependecy is created - foreach ($this->configData as $prefix => $config) { - $this->parseConfig($prefix); - $this->Application->HandleEvent( new kEvent($prefix.':OnAfterConfigRead') ); - } - } - function CacheParsedData() { $event_manager =& $this->Application->recallObject('EventManager'); @@ -200,16 +71,6 @@ $conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("configs_parsed", '.$conn->qstr(serialize($cache)).', '.adodb_mktime().')'); } - function ResetParsedData($include_sections=false) - { - $conn =& $this->Application->GetADODBConnection(); - $conn->Query('DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName = "configs_parsed"'); - - if ($include_sections) { - $conn->Query('DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName = "sections_parsed"'); - } - } - function RestoreParsedData() { $conn =& $this->Application->GetADODBConnection(); @@ -244,6 +105,37 @@ else return false; } + function ResetParsedData($include_sections=false) + { + $conn =& $this->Application->GetADODBConnection(); + $conn->Query('DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName = "configs_parsed"'); + + if ($include_sections) { + $conn->Query('DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName = "sections_parsed"'); + } + } + + function scanModules($folderPath) + { + if (defined('CACHE_PARSED_CONFIGS') && CACHE_PARSED_CONFIGS) { + $restored = $this->RestoreParsedData(); + if ($restored) return; + } + $this->includeConfigFiles(); + $this->ParseConfigs(); + + if (defined('CACHE_PARSED_CONFIGS')) { + $this->CacheParsedData(); + } + + if (defined('CACHE_CONFIGS_FILES') && $files_cached == 0) { + $conn =& $this->Application->GetADODBConnection(); + $conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_files", '.$conn->qstr(serialize($this->configFiles)).', '.adodb_mktime().')'); + } + + unset($this->configFiles); + } + function findConfigFiles($folderPath) { // if FULL_PATH = "/" ensure, that all "/" in $folderPath are not deleted @@ -267,6 +159,44 @@ } } + /** + * Read configs from all directories + * on path specified + * + * @param string $folderPath + * @access public + */ + /*function processFolder($folderPath, $cached) + { + $fh = opendir($folderPath); + while (($sub_folder = readdir($fh))) { + $full_path = $folderPath.'/'.$sub_folder; + if( $this->isDir($full_path) && file_exists($this->getConfigName($full_path)) ) + { + if (filemtime($full_path) > $cached) { + $this->CacheExpired = true; + + $file = $this->getConfigName($full_path); + if ( $this->Application->isDebugMode() && constOn('DBG_PROFILE_INCLUDES') ) + { + + if ( in_array($file, get_required_files()) ) return; + global $debugger; + include_once(FULL_PATH.$file); + } + else { + include_once($file); + } + + if ( !isset($config) || !$config ) continue; + $prefix = $config['Prefix']; + $config['BasePath'] = $full_path; + $this->configData[$prefix] = $config; + } + } + } + }*/ + function includeConfigFiles() { $this->Application->refreshModuleInfo(); @@ -291,25 +221,15 @@ } } - function scanModules($folderPath) + function ParseConfigs() { - if (defined('CACHE_PARSED_CONFIGS') && CACHE_PARSED_CONFIGS) { - $restored = $this->RestoreParsedData(); - if ($restored) return; +// $this->parseConfig('formatters'); // !TEMPORARY!, until config dependecy is created + foreach ($this->configData as $prefix => $config) { + $this->parseConfig($prefix); } - $this->includeConfigFiles(); - $this->ParseConfigs(); - - if (defined('CACHE_PARSED_CONFIGS')) { - $this->CacheParsedData(); + foreach ($this->configData as $prefix => $config) { + $this->Application->HandleEvent( new kEvent($prefix.':OnAfterConfigRead') ); } - - if (defined('CACHE_CONFIGS_FILES') && $files_cached == 0) { - $conn =& $this->Application->GetADODBConnection(); - $conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_files", '.$conn->qstr(serialize($this->configFiles)).', '.adodb_mktime().')'); - } - - unset($this->configFiles); } /** @@ -426,6 +346,44 @@ } } + function postProcessConfig($prefix, $config_key, $dst_prefix_var) + { + $main_config =& $this->configData[$prefix]; + $sub_configs = getArrayValue($main_config, $config_key); + if (!$sub_configs) { + return false; + } + unset($main_config[$config_key]); + + foreach ($sub_configs as $sub_prefix => $sub_config) { + if ($config_key == 'AggregateConfigs' && !isset($this->configData[$sub_prefix])) { + $this->loadConfig($sub_prefix); + } + $sub_config['Prefix'] = $sub_prefix; + $this->configData[$sub_prefix] = array_merge_recursive2($this->configData[$$dst_prefix_var], $sub_config); + + // when merging empty array to non-empty results non-empty array, but empty is required + foreach ($sub_config as $sub_key => $sub_value) { + if (!$sub_value) { + unset($this->configData[$sub_prefix][$sub_key]); + } + } + if ($config_key == 'Clones') { + $this->prefixFiles[$sub_prefix] = $this->prefixFiles[$prefix]; + } + + $this->postProcessConfig($sub_prefix, $config_key, $dst_prefix_var); + if ($config_key == 'AggregateConfigs') { + $this->postProcessConfig($sub_prefix, 'Clones', 'prefix'); + } + } + + if (!$prefix) { + // configs, that used only for cloning & not used ifself + unset($this->configData[$prefix]); + } + } + function loadConfigFile($filename) { $config_found = file_exists(FULL_PATH.$filename) && $this->configAllowed($filename); @@ -580,7 +538,42 @@ return $ret && is_dir($folderPath); } + /** + * Checks if config file is allowed for includion (if module of config is installed) + * + * @param string $config_path relative path from in-portal directory + */ + function configAllowed($config_path) + { + $module_found = false; + if (!$this->Application->ModuleInfo) return false; + foreach($this->Application->ModuleInfo as $module_name => $module_info) + { + $module_path = '/'.$module_info['Path']; + if (preg_match('/^'.preg_quote($module_path, '/').'/', $config_path)) { + // if (substr($config_path, 0, strlen($module_path)) == $module_path) { + // config file path starts with module folder path + $module_found = true; + break; + } + } + return $module_found; + } + + /** + * Returns true if config exists and is allowed for reading + * + * @param string $prefix + * @return bool + */ + function prefixRegistred($prefix) + { + return isset($this->configData[$prefix]) ? true : false; + } + + + }