Added proper support for CI controllers
authorAlexander Ebert <ebert@woltlab.com>
Wed, 8 Jun 2016 10:18:28 +0000 (12:18 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 8 Jun 2016 10:18:37 +0000 (12:18 +0200)
wcfsetup/install/files/lib/system/request/ControllerMap.class.php

index eb2d185586078ebd1bce0c70bfaeed13dcd14925..87a2f54a6f0f71d5487fa046b2d6cb5bdb1ddf5f 100644 (file)
@@ -66,15 +66,19 @@ class ControllerMap extends SingletonFactory {
                        throw new SystemException("Malformed controller name '" . $controller . "'");
                }
                
-               $parts = explode('-', $controller);
-               $parts = array_map('ucfirst', $parts);
-               $controller = implode('', $parts);
-               
-               if ($controller === 'AjaxProxy') $controller = 'AJAXProxy';
-               
-               $classData = $this->getClassData($application, $controller, $isAcpRequest, 'page');
-               if ($classData === null) $classData = $this->getClassData($application, $controller, $isAcpRequest, 'form');
-               if ($classData === null) $classData = $this->getClassData($application, $controller, $isAcpRequest, 'action');
+               $classData = $this->getLegacyClassData($application, $controller, $isAcpRequest);
+               if ($classData === null) {
+                       $parts = explode('-', $controller);
+                       $parts = array_map('ucfirst', $parts);
+                       $controller = implode('', $parts);
+                       
+                       // work-around for upgrade path 2.1 -> 2.2
+                       if ($controller === 'AjaxProxy') $controller = 'AJAXProxy';
+                       
+                       $classData = $this->getClassData($application, $controller, $isAcpRequest, 'page');
+                       if ($classData === null) $classData = $this->getClassData($application, $controller, $isAcpRequest, 'form');
+                       if ($classData === null) $classData = $this->getClassData($application, $controller, $isAcpRequest, 'action');
+               }
                
                if ($classData === null) {
                        throw new SystemException("Unknown controller '" . $controller . "'");
@@ -269,6 +273,32 @@ class ControllerMap extends SingletonFactory {
                return true;
        }
        
+       /**
+        * Lookups the list of legacy controller names that violate the name
+        * schema, e.g. are named 'BBCodeList' instead of `BbCodeList`.
+        * 
+        * @param       string          $application    application identifier
+        * @param       string          $controller     controller name
+        * @param       boolean         $isAcpRequest   true if this is an ACP request
+        * @return      string[]|null   className, controller and pageType, or null if this is not a legacy controller name
+        */
+       protected function getLegacyClassData($application, $controller, $isAcpRequest) {
+               $environment = ($isAcpRequest) ? 'acp' : 'frontend';
+               if (isset($this->ciControllers['lookup'][$application][$environment][$controller])) {
+                       $className = $this->ciControllers['lookup'][$application][$environment][$controller];
+                       
+                       if (preg_match('~\\\\(?P<controller>[^\\\\]+)(?P<pageType>Action|Form|Page)$~', $className, $matches)) {
+                               return [
+                                       'className' => $className,
+                                       'controller' => $matches['controller'],
+                                       'pageType' => strtolower($matches['pageType'])
+                               ];
+                       }
+               }
+               
+               return null;
+       }
+       
        /**
         * Returns the class data for the active request or null if for the given
         * configuration no proper class exist.