From 578513198ff9daf726135aeda85eb8c94342aaa3 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 8 Jun 2016 12:18:28 +0200 Subject: [PATCH] Added proper support for CI controllers --- .../system/request/ControllerMap.class.php | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/lib/system/request/ControllerMap.class.php b/wcfsetup/install/files/lib/system/request/ControllerMap.class.php index eb2d185586..87a2f54a6f 100644 --- a/wcfsetup/install/files/lib/system/request/ControllerMap.class.php +++ b/wcfsetup/install/files/lib/system/request/ControllerMap.class.php @@ -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[^\\\\]+)(?PAction|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. -- 2.20.1