From 79be560d7d73941cc5f19d4bb6c9db927b6aae0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 27 May 2022 14:54:12 +0200 Subject: [PATCH] Remove magic numbers from RoutingCacheBuilder's landingPages data --- .../builder/RoutingCacheBuilder.class.php | 26 ++++++++++++------- .../system/request/ControllerMap.class.php | 12 ++++----- 2 files changed, 23 insertions(+), 15 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 0a17b72ca7..dc00f85cc2 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php @@ -266,7 +266,7 @@ class RoutingCacheBuilder extends AbstractCacheBuilder } $cmsPageID = 0; - if (\preg_match('~^__WCF_CMS__(\d+)$~', $landingPages['wcf'][0], $matches)) { + if (\preg_match('~^__WCF_CMS__(\d+)$~', $landingPages['wcf']['controller'], $matches)) { $cmsPageID = $matches[1]; } @@ -289,7 +289,7 @@ class RoutingCacheBuilder extends AbstractCacheBuilder // Discard the custom url if this CMS page is the landing page of its associated app. if ( !empty($landingPages[$abbreviation]) - && $landingPages[$abbreviation][0] === '__WCF_CMS__' . $row['pageID'] + && $landingPages[$abbreviation]['controller'] === '__WCF_CMS__' . $row['pageID'] && !$row['languageID'] ) { $customUrl = ''; @@ -354,7 +354,11 @@ class RoutingCacheBuilder extends AbstractCacheBuilder $controller = $page->controller; } else { $controller = '__WCF_CMS__' . $page->pageID; - $controller = [$controller, $controller, CmsPage::class]; + $controller = [ + 'controller' => $controller, + 'routePart' => $controller, + 'className' => CmsPage::class, + ]; } } else { if ($application->landingPageID) { @@ -364,7 +368,11 @@ class RoutingCacheBuilder extends AbstractCacheBuilder $controller = $page->controller; } else { $controller = '__WCF_CMS__' . $page->pageID; - $controller = [$controller, $controller, CmsPage::class]; + $controller = [ + 'controller' => $controller, + 'routePart' => $controller, + 'className' => CmsPage::class, + ]; } } } @@ -376,11 +384,11 @@ class RoutingCacheBuilder extends AbstractCacheBuilder if (\is_string($controller)) { $fqnController = $controller; - $controller = $this->classNameToControllerName($fqnController); + $controller = $this->classNameToControllerName($controller); $controller = [ - $controller, - ControllerMap::transformController($controller), - $fqnController, + 'controller' => $controller, + 'routePart' => ControllerMap::transformController($controller), + 'className' => $fqnController, ]; } @@ -396,7 +404,7 @@ class RoutingCacheBuilder extends AbstractCacheBuilder return $data; } - $landingPageController = $data['landingPages']['wcf'][0]; + $landingPageController = $data['landingPages']['wcf']['controller']; $controllers = [$landingPageController]; // The controller may be the custom url of a CMS page. diff --git a/wcfsetup/install/files/lib/system/request/ControllerMap.class.php b/wcfsetup/install/files/lib/system/request/ControllerMap.class.php index 2f8c6bbbc6..4d45643911 100644 --- a/wcfsetup/install/files/lib/system/request/ControllerMap.class.php +++ b/wcfsetup/install/files/lib/system/request/ControllerMap.class.php @@ -255,7 +255,7 @@ class ControllerMap extends SingletonFactory public function lookupDefaultController($application) { $data = $this->landingPages[$application]; - $controller = $data[1]; + $controller = $data['routePart']; if ($application === 'wcf' && empty($controller)) { return null; @@ -302,7 +302,7 @@ class ControllerMap extends SingletonFactory } return [ - 'application' => \mb_substr($data[2], 0, \mb_strpos($data[2], '\\')), + 'application' => \mb_substr($data['className'], 0, \mb_strpos($data['className'], '\\')), 'controller' => $controller, ]; } @@ -327,7 +327,7 @@ class ControllerMap extends SingletonFactory return false; } else { if ( - $matches['controller'] == $this->landingPages[$application][0] + $matches['controller'] == $this->landingPages[$application]['controller'] && isset($this->customUrls['lookup'][$application]['']) && $this->customUrls['lookup'][$application][''] !== $controller ) { @@ -344,7 +344,7 @@ class ControllerMap extends SingletonFactory } } - if ($this->landingPages[$application][0] === $controller) { + if ($this->landingPages[$application]['controller'] === $controller) { return true; } @@ -359,13 +359,13 @@ class ControllerMap extends SingletonFactory */ public function isLandingPage(string $className, array $metaData) { - if ($className !== $this->landingPages['wcf'][2]) { + if ($className !== $this->landingPages['wcf']['className']) { return false; } if ($className === CmsPage::class) { // check if page id matches - if ($this->landingPages['wcf'][1] !== '__WCF_CMS__' . $metaData['cms']['pageID']) { + if ($this->landingPages['wcf']['routePart'] !== '__WCF_CMS__' . $metaData['cms']['pageID']) { return false; } } -- 2.20.1