Index: branches/5.0.x/core/kernel/utility/unit_config_reader.php =================================================================== diff -u -r12277 -r12294 --- branches/5.0.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 12277) +++ branches/5.0.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 12294) @@ -1,6 +1,6 @@ $this->Application->ConfigCacheIds, 'Application.ConfigHash' => $this->Application->ConfigHash, 'Application.ReplacementTemplates' => $this->Application->ReplacementTemplates, + 'Application.RewriteListeners' => $this->Application->RewriteListeners, 'Application.ModuleInfo' => $this->Application->ModuleInfo, ); @@ -153,6 +154,7 @@ $this->Application->ConfigCacheIds = $cache['Application.ConfigCacheIds']; $this->Application->ReplacementTemplates = $cache['Application.ReplacementTemplates']; + $this->Application->RewriteListeners = $cache['Application.RewriteListeners']; $this->Application->ModuleInfo = $cache['Application.ModuleInfo']; @@ -336,6 +338,7 @@ } if ($store_cache) { + $this->_sortRewriteListeners(); $this->CacheParsedData(); if ($this->Application->isDebugMode(false) && constOn('DBG_VALIDATE_CONFIGS')) { @@ -352,6 +355,34 @@ } /** + * Sort rewrite listeners according to RewritePriority (non-prioritized listeners goes first) + * + */ + function _sortRewriteListeners() + { + $listeners = Array (); + $prioritized_listeners = Array (); + + // process non-prioritized listeners + foreach ($this->Application->RewriteListeners as $prefix => $listener_data) { + if ($listener_data['priority'] === false) { + $listeners[$prefix] = $listener_data; + } + else { + $prioritized_listeners[$prefix] = $listener_data['priority']; + } + } + + // process prioritized listeners + asort($prioritized_listeners); + foreach ($prioritized_listeners as $prefix => $priority) { + $listeners[$prefix] = $this->Application->RewriteListeners[$prefix]; + } + + $this->Application->RewriteListeners = $listeners; + } + + /** * Re-reads all configs * */ @@ -514,10 +545,22 @@ } } - if (isset($config['ReplacementTemplates']) && $config['ReplacementTemplates']) { + if (array_key_exists('ReplacementTemplates', $config) && $config['ReplacementTemplates']) { // replacement templates defined in this config - $this->Application->ReplacementTemplates = array_merge_recursive2($this->Application->ReplacementTemplates, $config['ReplacementTemplates']); + $this->Application->ReplacementTemplates = array_merge($this->Application->ReplacementTemplates, $config['ReplacementTemplates']); } + + if (array_key_exists('RewriteListener', $config) && $config['RewriteListener']) { + // replacement templates defined in this config + $rewrite_listener = $config['RewriteListener']; + if (strpos($rewrite_listener, ':') === false) { + $rewrite_listener = $prefix . '_EventHandler:' . $rewrite_listener; + } + + $rewrite_priority = array_key_exists('RewritePriority', $config) ? $config['RewritePriority'] : false; + + $this->Application->RewriteListeners[$prefix] = Array ('listener' => $rewrite_listener, 'priority' => $rewrite_priority); + } } function ValidateConfig($prefix)