Index: branches/5.3.x/core/kernel/utility/unit_config_reader.php =================================================================== diff -u -N -r15910 -r16171 --- branches/5.3.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 15910) +++ branches/5.3.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 16171) @@ -1,6 +1,6 @@ include all unit configs to create it ! $this->includeConfigFiles($folder_path, $cache); $this->parseConfigs(); + $this->sortRouters(); // tell AfterConfigRead to store cache if needed // can't store it here because AfterConfigRead needs ability to change config data @@ -166,10 +167,6 @@ if ( !$this->Application->InitDone ) { // scanModules is called multiple times during installation process $this->Application->InitManagers(); - - // get build-in rewrite listeners ONLY to be able to parse mod-rewrite url when unit config cache is missing - $this->retrieveCollections(); - $this->sortRewriteListeners(); } $this->Application->cacheManager->applyDelayedUnitProcessing(); @@ -360,8 +357,6 @@ } if ( $store_cache ) { - $this->sortRewriteListeners(); - $this->Application->HandleEvent(new kEvent('adm:OnAfterCacheRebuild')); $this->Application->cacheManager->UpdateUnitCache(); @@ -379,36 +374,66 @@ } /** - * Sort rewrite listeners according to RewritePriority (non-prioritized listeners goes first) + * Sort routers according to their weight (non-prioritized routers goes first). * * @return void */ - protected function sortRewriteListeners() + protected function sortRouters() { - $listeners = array(); - $prioritized_listeners = array(); + $sorted_routers = array(); + $prioritized_routers = array(); + $routers = $this->collectRouters(); - // process non-prioritized listeners - foreach ( $this->Application->RewriteListeners as $prefix => $listener_data ) { - if ( $listener_data['priority'] === false ) { - $listeners[$prefix] = $listener_data; + // Process non-prioritized routers. + foreach ( $routers as $prefix => $router_data ) { + if ( $router_data['priority'] === false ) { + $sorted_routers[$prefix] = $router_data; } else { - $prioritized_listeners[$prefix] = $listener_data['priority']; + $prioritized_routers[$prefix] = $router_data['priority']; } } - // process prioritized listeners - asort($prioritized_listeners, SORT_NUMERIC); + // Process prioritized routers. + asort($prioritized_routers, SORT_NUMERIC); - foreach ( $prioritized_listeners as $prefix => $priority ) { - $listeners[$prefix] = $this->Application->RewriteListeners[$prefix]; + foreach ( $prioritized_routers as $prefix => $priority ) { + $sorted_routers[$prefix] = $routers[$prefix]; } - $this->Application->RewriteListeners = $listeners; + $this->Application->routers = $sorted_routers; } /** + * Collects routers. + * + * @return array + */ + protected function collectRouters() + { + $routers = array(); + $router_classes = $this->Application->getSubClasses('AbstractRouter'); + + foreach ( $router_classes as $router_class ) { + if ( !class_exists($router_class) ) { + // This can happen, when: + // - router class (coming from cache) was renamed; + // - new cache is built based on outdated class map. + continue; + } + + /** @var AbstractRouter $router */ + $router = new $router_class(); + $routers[$router->getPrefix()] = array( + 'class' => $router_class, + 'priority' => $router->getWeight(), + ); + } + + return $routers; + } + + /** * Re-reads all configs. * * @return void @@ -424,6 +449,7 @@ $this->afterConfigProcessed = array(); $this->includeConfigFiles(MODULES_PATH, false); $this->parseConfigs(); + $this->sortRouters(); $this->AfterConfigRead(false); $this->cloner->processDynamicallyAdded(); $this->retrieveCollections(); @@ -440,26 +466,6 @@ if ( $config->getReplacementTemplates() ) { $this->Application->ReplacementTemplates = array_merge($this->Application->ReplacementTemplates, $config->getReplacementTemplates()); } - - // collect rewrite listeners - if ( $config->getRewriteListener() ) { - $rewrite_listeners = $config->getRewriteListener(); - - if ( !is_array($rewrite_listeners) ) { - // when one method is used to build and parse url - $rewrite_listeners = array($rewrite_listeners, $rewrite_listeners); - } - - foreach ( $rewrite_listeners as $index => $rewrite_listener ) { - if ( strpos($rewrite_listener, ':') === false ) { - $rewrite_listeners[$index] = $prefix . '_EventHandler:' . $rewrite_listener; - } - } - - $rewrite_priority = $config->getRewritePriority(); - - $this->Application->RewriteListeners[$prefix] = array('listener' => $rewrite_listeners, 'priority' => $rewrite_priority); - } } } @@ -720,4 +726,4 @@ return $this->prefixFiles[$prefix]; } -} \ No newline at end of file +}