Skip to content

Commit 24c2984

Browse files
committed
Added middleware for Ukraine
1 parent 962dcb4 commit 24c2984

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

app/Http/Middleware/UkraineMirror.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use App\Services\Mirror;
6+
use Closure;
7+
use Illuminate\Http\Request;
8+
use Symfony\Component\HttpFoundation\Response;
9+
10+
class UkraineMirror
11+
{
12+
public function __construct(protected Mirror $mirror) {}
13+
14+
/**
15+
* Handle an incoming request.
16+
*
17+
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
18+
*/
19+
public function handle(Request $request, Closure $next): Response
20+
{
21+
if ($this->mirror->hasMirror()) {
22+
config()->set('cache.default', 'null');
23+
}
24+
25+
return $next($request);
26+
}
27+
}

app/Services/Mirror.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Services;
4+
5+
use Illuminate\Support\Facades\Request;
6+
7+
class Mirror
8+
{
9+
/**
10+
* Проверяет, является ли текущий запрос зеркалом основного сайта.
11+
*
12+
* @return bool
13+
*/
14+
public function hasMirror(): bool
15+
{
16+
return $this->isMirror(Request::fullUrl(), config('app.url'));
17+
}
18+
19+
/**
20+
* Определяет, является ли URL зеркалом по домену.
21+
*
22+
* @param string $currentUrl
23+
* @param string $baseUrl
24+
* @return bool
25+
*/
26+
protected function isMirror(string $currentUrl, string $baseUrl): bool
27+
{
28+
return parse_url($baseUrl, PHP_URL_HOST) !== parse_url($currentUrl, PHP_URL_HOST);
29+
}
30+
}

0 commit comments

Comments
 (0)