Remove magic numbers from RoutingCacheBuilder's landingPages data
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 27 May 2022 12:54:12 +0000 (14:54 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 27 May 2022 12:58:42 +0000 (14:58 +0200)
wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php
wcfsetup/install/files/lib/system/request/ControllerMap.class.php

index 0a17b72ca7533eb2d1b790bc1ed675446b772418..dc00f85cc2b91fe10388a0e90ddbd3273a6c5dc6 100644 (file)
@@ -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.
index 2f8c6bbbc601a9a200dea4960126d37bd903e26a..4d456439119a1fc875a84124de799ac5c2f08552 100644 (file)
@@ -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;
             }
         }