]> BookStack Code Mirror - bookstack/blob - app/Http/Middleware/StartSessionExtended.php
Themes: Documented public file serving
[bookstack] / app / Http / Middleware / StartSessionExtended.php
1 <?php
2
3 namespace BookStack\Http\Middleware;
4
5 use Illuminate\Http\Request;
6 use Illuminate\Session\Middleware\StartSession as Middleware;
7
8 /**
9  * An extended version of the default Laravel "StartSession" middleware
10  * with customizations applied as required:
11  *
12  * - Adds filtering for the request URLs stored in session history.
13  */
14 class StartSessionExtended extends Middleware
15 {
16     protected static array $pathPrefixesExcludedFromHistory = [
17         'uploads/images/'
18     ];
19
20     /**
21      * @inheritdoc
22      */
23     protected function storeCurrentUrl(Request $request, $session): void
24     {
25         $requestPath = strtolower($request->path());
26         foreach (static::$pathPrefixesExcludedFromHistory as $excludedPath) {
27             if (str_starts_with($requestPath, $excludedPath)) {
28                 return;
29             }
30         }
31
32         parent::storeCurrentUrl($request, $session);
33     }
34 }