From ea60fe4a9bb5d1879763c2158f9a7c94350d9783 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 27 May 2022 14:09:38 +0200 Subject: [PATCH] DRY up the conversion of class name to controller name in RoutingCacheBuilder --- .../builder/RoutingCacheBuilder.class.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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); + } } -- 2.20.1