-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |