]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Request.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / app / Http / Request.php
index bd2761a0b5cfcd9fe8f8dec6149ddf0a3a9e5315..c2d430279fb08db23f91b3ec06574d9e6bf21f46 100644 (file)
@@ -1,26 +1,41 @@
-<?php namespace BookStack\Http;
+<?php
+
+namespace BookStack\Http;
 
 use Illuminate\Http\Request as LaravelRequest;
 
 class Request extends LaravelRequest
 {
-
     /**
      * Override the default request methods to get the scheme and host
-     * to set the custom APP_URL, if set.
-     * @return \Illuminate\Config\Repository|mixed|string
+     * to directly use the custom APP_URL, if set.
      */
-    public function getSchemeAndHttpHost()
+    public function getSchemeAndHttpHost(): string
     {
-        $base = config('app.url', null);
+        $appUrl = config('app.url', null);
 
-        if ($base) {
-            $base = trim($base, '/');
-        } else {
-            $base = $this->getScheme().'://'.$this->getHttpHost();
+        if ($appUrl) {
+            return implode('/', array_slice(explode('/', $appUrl), 0, 3));
         }
 
-        return $base;
+        return parent::getSchemeAndHttpHost();
     }
 
-}
\ No newline at end of file
+    /**
+     * Override the default request methods to get the base URL
+     * to directly use the custom APP_URL, if set.
+     * The base URL never ends with a / but should start with one if not empty.
+     */
+    public function getBaseUrl(): string
+    {
+        $appUrl = config('app.url', null);
+
+        if ($appUrl) {
+            $parsedBaseUrl = rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/');
+
+            return empty($parsedBaseUrl) ? '' : ('/' . $parsedBaseUrl);
+        }
+
+        return parent::getBaseUrl();
+    }
+}