Skip to content

Commit

Permalink
Added middleware for Ukraine
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Jan 26, 2025
1 parent 962dcb4 commit 24c2984
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/Http/Middleware/UkraineMirror.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Http\Middleware;

use App\Services\Mirror;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class UkraineMirror
{
public function __construct(protected Mirror $mirror) {}

/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if ($this->mirror->hasMirror()) {
config()->set('cache.default', 'null');
}

return $next($request);
}
}
30 changes: 30 additions & 0 deletions app/Services/Mirror.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Services;

use Illuminate\Support\Facades\Request;

class Mirror
{
/**
* Проверяет, является ли текущий запрос зеркалом основного сайта.
*
* @return bool
*/
public function hasMirror(): bool
{
return $this->isMirror(Request::fullUrl(), config('app.url'));
}

/**
* Определяет, является ли URL зеркалом по домену.
*
* @param string $currentUrl
* @param string $baseUrl
* @return bool
*/
protected function isMirror(string $currentUrl, string $baseUrl): bool
{
return parse_url($baseUrl, PHP_URL_HOST) !== parse_url($currentUrl, PHP_URL_HOST);
}
}

0 comments on commit 24c2984

Please sign in to comment.