-
-
Notifications
You must be signed in to change notification settings - Fork 568
/
Copy pathController.php
39 lines (30 loc) · 1019 Bytes
/
Controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace Statamic\StaticCaching\NoCache;
use Illuminate\Http\Request;
use Statamic\StaticCaching\Replacers\NoCacheReplacer;
use Statamic\Support\Str;
class Controller
{
public function __invoke(Request $request, Session $session)
{
$url = $request->input('url');
if (config('statamic.static_caching.ignore_query_strings', false)) {
$url = explode('?', $url)[0];
}
if (Str::endsWith($url, '?')) {
$url = Str::replaceLast('?', '', $url);
}
if (Str::contains($url, '?')) {
$url = Str::before($url, '?').'?'.Request::normalizeQueryString(Str::after($url, '?'));
}
$session = $session->setUrl($url)->restore();
$replacer = new NoCacheReplacer($session);
return [
'csrf' => csrf_token(),
'regions' => $session
->regions()
->map->render()
->map(fn ($contents) => $replacer->replace($contents)),
];
}
}