Fixed controller names if Route is used w/o compatibility mode
authorAlexander Ebert <ebert@woltlab.com>
Mon, 23 Feb 2015 10:32:55 +0000 (11:32 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 23 Feb 2015 10:32:55 +0000 (11:32 +0100)
wcfsetup/install/files/lib/system/request/Route.class.php

index dea54b67341d0bf7ac295ff843448331973ff84f..ee75593a58f8483e0f079fc5f9e6cf9b6e0ceec7 100644 (file)
@@ -55,6 +55,12 @@ class Route implements IRoute {
         */
        protected $routeData = null;
        
+       /**
+        * cached list of transformed controller names
+        * @var array<string>
+        */
+       protected static $controllerNames = array();
+       
        /**
         * list of application abbreviation and default controller name
         * @var array<string>
@@ -301,6 +307,11 @@ class Route implements IRoute {
                                        continue;
                                }
                                
+                               // handle controller names
+                               if (!URL_LEGACY_MODE && $component === 'controller') {
+                                       $components[$component] = $this->getControllerName($application, $components[$component]);
+                               }
+                               
                                // handle built-in SEO
                                if ($component === 'id' && isset($components['title'])) {
                                        $link .= $components[$component] . '-' . $components['title'] . '/';
@@ -340,6 +351,24 @@ class Route implements IRoute {
                return $this->isACP;
        }
        
+       /**
+        * Returns the transformed controller name.
+        *
+        * @param       string          $application
+        * @param       string          $controller
+        * @return      string
+        */
+       protected function getControllerName($application, $controller) {
+               if (!isset(self::$controllerNames[$controller])) {
+                       $controllerName = RequestHandler::getTokenizedController($controller);
+                       $alias = (!$this->isACP) ? RequestHandler::getInstance()->getAliasByController($controllerName) : null;
+                       
+                       self::$controllerNames[$controller] = ($alias) ?: $controllerName;
+               }
+               
+               return self::$controllerNames[$controller];
+       }
+       
        /**
         * Loads the default controllers for each active application.
         */