DRY up abbreviation retrieval in RoutingCacheBuilder::getCustomUrls()
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 27 May 2022 12:19:50 +0000 (14:19 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 27 May 2022 12:19:50 +0000 (14:19 +0200)
wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php

index 0a25021a5dbb3bf8cfeb0da0cc550dc2097475cc..49026d194f180c23117c0874720e15fd97e81daa 100644 (file)
@@ -270,42 +270,39 @@ class RoutingCacheBuilder extends AbstractCacheBuilder
             $cmsPageID = $matches[1];
         }
 
-        $abbreviations = [];
         foreach ($rows as $row) {
             $customUrl = FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($row['controllerCustomURL']));
             $packageID = $row['applicationPackageID'];
-            if (!isset($abbreviations[$packageID])) {
-                $abbreviations[$packageID] = ApplicationHandler::getInstance()->getAbbreviation($packageID);
-            }
+            $abbreviation = ApplicationHandler::getInstance()->getAbbreviation($packageID);
 
-            if (!isset($data['lookup'][$abbreviations[$packageID]])) {
-                $data['lookup'][$abbreviations[$packageID]] = [];
-                $data['reverse'][$abbreviations[$packageID]] = [];
+            if (!isset($data['lookup'][$abbreviation])) {
+                $data['lookup'][$abbreviation] = [];
+                $data['reverse'][$abbreviation] = [];
             }
 
             if (isset($row['controller'])) {
-                $data['lookup'][$abbreviations[$packageID]][$customUrl] = $row['controller'];
-                $data['reverse'][$abbreviations[$packageID]][$this->classNameToControllerName($row['controller'])] = $customUrl;
+                $data['lookup'][$abbreviation][$customUrl] = $row['controller'];
+                $data['reverse'][$abbreviation][$this->classNameToControllerName($row['controller'])] = $customUrl;
             } else {
                 $cmsIdentifier = '__WCF_CMS__' . $row['pageID'] . '-' . ($row['languageID'] ?: 0);
 
                 // Discard the custom url if this CMS page is the landing page of its associated app.
                 if (
-                    !empty($landingPages[$abbreviations[$packageID]])
-                    && $landingPages[$abbreviations[$packageID]][0] === '__WCF_CMS__' . $row['pageID']
+                    !empty($landingPages[$abbreviation])
+                    && $landingPages[$abbreviation][0] === '__WCF_CMS__' . $row['pageID']
                     && !$row['languageID']
                 ) {
                     $customUrl = '';
                 }
-                $data['reverse'][$abbreviations[$packageID]][$cmsIdentifier] = $customUrl;
+                $data['reverse'][$abbreviation][$cmsIdentifier] = $customUrl;
 
-                if ($cmsPageID && $abbreviations[$packageID] === 'wcf') {
+                if ($cmsPageID && $abbreviation === 'wcf') {
                     if ($customUrl === '' && $cmsPageID != $row['pageID']) {
                         continue;
                     }
                 }
 
-                $data['lookup'][$abbreviations[$packageID]][$customUrl] = $cmsIdentifier;
+                $data['lookup'][$abbreviation][$customUrl] = $cmsIdentifier;
             }
         }