From: Tim Düsterhus Date: Fri, 27 May 2022 12:09:38 +0000 (+0200) Subject: DRY up the conversion of class name to controller name in RoutingCacheBuilder X-Git-Tag: 6.0.0_Alpha_1~1251 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ea60fe4a9bb5d1879763c2158f9a7c94350d9783;p=GitHub%2FWoltLab%2FWCF.git DRY up the conversion of class name to controller name in RoutingCacheBuilder --- diff --git a/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php index 30da257966..91cece6b63 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php @@ -94,8 +94,7 @@ class RoutingCacheBuilder extends AbstractCacheBuilder $overrideApplication = $abbreviations[$row['overrideApplicationPackageID']]; if ($row['pageType'] === 'system') { - $tmp = \explode('\\', $row['controller']); - $controller = \preg_replace('/(?:Action|Form|Page)$/', '', \array_pop($tmp)); + $controller = $this->classNameToControllerName($row['controller']); $data['lookup'][$overrideApplication][$controller] = $application; $data['reverse'][$application][$controller] = $overrideApplication; @@ -288,11 +287,7 @@ class RoutingCacheBuilder extends AbstractCacheBuilder if (isset($row['controller'])) { $data['lookup'][$abbreviations[$packageID]][$customUrl] = $row['controller']; - $data['reverse'][$abbreviations[$packageID]][\preg_replace( - '~^.*?([A-Za-z0-9]+)(?:Action|Form|Page)~', - '$1', - $row['controller'] - )] = $customUrl; + $data['reverse'][$abbreviations[$packageID]][$this->classNameToControllerName($row['controller'])] = $customUrl; } else { $cmsIdentifier = '__WCF_CMS__' . $row['pageID'] . '-' . ($row['languageID'] ?: 0); @@ -386,7 +381,7 @@ class RoutingCacheBuilder extends AbstractCacheBuilder if (\is_string($controller)) { $fqnController = $controller; - $controller = \preg_replace('~^.*?\\\([^\\\]+)(?:Action|Form|Page)$~', '\\1', $controller); + $controller = $this->classNameToControllerName($fqnController); $controller = [ $controller, ControllerMap::transformController($controller), @@ -433,4 +428,12 @@ class RoutingCacheBuilder extends AbstractCacheBuilder return $data; } + + /** + * @since 5.6 + */ + private function classNameToControllerName(string $className): string + { + return \preg_replace('~^.*?\\\([^\\\]+)(?:Action|Form|Page)$~', '\\1', $className); + } }