Browse Source

fix the url resolution on devmode without a trailing slash

Olivier Massot 4 years ago
parent
commit
691ac4b949
1 changed files with 27 additions and 7 deletions
  1. 27 7
      ot_core/Classes/Website/OtWebsiteRepository.php

+ 27 - 7
ot_core/Classes/Website/OtWebsiteRepository.php

@@ -206,15 +206,19 @@ class OtWebsiteRepository
      * file of the given website
      *
      * @param array $website
+     * @param string|null $identifier
      * @return Site
      * @throws InvalidWebsiteConfigurationException
+     * @throws NoSuchRecordException
      */
-    public function generateWebsiteConfiguration(array $website): Site
+    public function generateWebsiteConfiguration(array $website, string $identifier = null): Site
     {
         $rootUid = $this->getWebsiteRootUid($website['uid']);
 
+        $identifier = $identifier ?? $website['config_identifier'];
+
         return new Site(
-            $website['config_identifier'],
+            $identifier,
             $rootUid,
             [
                 'base' => $this->resolveWebsiteBaseUri($website),
@@ -345,6 +349,7 @@ class OtWebsiteRepository
 
         $tail = $uri->getPath();
         if ($devMode) {
+            $tail = rtrim($tail, '/') . '/';
             $tail = preg_replace("/\/?[\w\-]+\/(.*)/", "/$1", $tail);
         }
 
@@ -363,11 +368,24 @@ class OtWebsiteRepository
      * and parse it.
      *
      * @param int $rootUid
+     * @param string|null $identifier
      * @return array   Path of the configuration file and parsed configuration of the website
      */
-    public function findConfigFileAndContentFor(int $rootUid): array
+    public function findConfigFileAndContentFor(int $rootUid, string $identifier = null): array
     {
         $configs_directory = $_ENV['TYPO3_PATH_APP'] . "/config/sites/";
+
+        if ($identifier !== null) {
+            $filename = $configs_directory . $identifier . "/config.yaml";
+            $yamlConfig = Yaml::parseFile($filename);
+
+            if ($yamlConfig['rootPageId'] === $rootUid) {
+                return [$filename, $yamlConfig];
+            } else {
+                throw new \RuntimeException("No configuration file found for identifier " . $identifier);
+            }
+        }
+
         $candidates = array_filter(
             scandir($configs_directory),
             function ($x) { return $x != '.' && $x != '..'; }
@@ -409,22 +427,24 @@ class OtWebsiteRepository
      * Similar to findConfigFileAndContentFor(), but only returns the parsed configuration
      *
      * @param int $rootUid
+     * @param string|null $identifier
      * @return array   Configuration of the website
      */
-    public function findConfigFor(int $rootUid): array
+    public function findConfigFor(int $rootUid, string $identifier = null): array
     {
-        $pathAndConfig = $this->findConfigFileAndContentFor($rootUid);
+        $pathAndConfig = $this->findConfigFileAndContentFor($rootUid, $identifier);
         return $pathAndConfig[1];
     }
 
     /**
      * Similar to findConfigFileAndContentFor(), but only returns the config file path
      * @param int $rootUid
+     * @param string|null $identifier
      * @return string   Path of the config file of the given website
      */
-    public function findConfigFilePathFor(int $rootUid): string
+    public function findConfigFilePathFor(int $rootUid, string $identifier = null): string
     {
-        $pathAndConfig = $this->findConfigFileAndContentFor($rootUid);
+        $pathAndConfig = $this->findConfigFileAndContentFor($rootUid, $identifier);
         return $pathAndConfig[0];
     }