]> BookStack Code Mirror - bookstack/blob - app/Http/Request.php
Merge branch 'fix/oidc-logout' into development
[bookstack] / app / Http / Request.php
1 <?php
2
3 namespace BookStack\Http;
4
5 use Illuminate\Http\Request as LaravelRequest;
6
7 class Request extends LaravelRequest
8 {
9     /**
10      * Override the default request methods to get the scheme and host
11      * to directly use the custom APP_URL, if set.
12      */
13     public function getSchemeAndHttpHost(): string
14     {
15         $appUrl = config('app.url', null);
16
17         if ($appUrl) {
18             return implode('/', array_slice(explode('/', $appUrl), 0, 3));
19         }
20
21         return parent::getSchemeAndHttpHost();
22     }
23
24     /**
25      * Override the default request methods to get the base URL
26      * to directly use the custom APP_URL, if set.
27      * The base URL never ends with a / but should start with one if not empty.
28      */
29     public function getBaseUrl(): string
30     {
31         $appUrl = config('app.url', null);
32
33         if ($appUrl) {
34             $parsedBaseUrl = rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/');
35
36             return empty($parsedBaseUrl) ? '' : ('/' . $parsedBaseUrl);
37         }
38
39         return parent::getBaseUrl();
40     }
41 }