File tree 2 files changed +57
-0
lines changed 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments