@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
final class EvaluationNavigation
|
||||
{
|
||||
public static function local(Request $request): bool
|
||||
{
|
||||
return app()->environment('payable-testing')
|
||||
&& in_array($request->ip(), ['127.0.0.1', '::1'], true)
|
||||
&& in_array($request->getHost(), ['127.0.0.1', 'localhost', '::1'], true);
|
||||
}
|
||||
|
||||
public static function returnPath(mixed $intended, Request $request): string
|
||||
{
|
||||
$fallback = '/dashboard';
|
||||
if (! is_string($intended) || preg_match('/[\x00-\x20\\\\]/', $intended)) {
|
||||
return $fallback;
|
||||
}
|
||||
$parts = parse_url($intended);
|
||||
if ($parts === false) {
|
||||
return $fallback;
|
||||
}
|
||||
if (isset($parts['scheme']) || isset($parts['host'])) {
|
||||
$port = $parts['port'] ?? (($parts['scheme'] ?? '') === 'https' ? 443 : 80);
|
||||
if (($parts['scheme'] ?? '') !== $request->getScheme() || ($parts['host'] ?? '') !== $request->getHost() || $port !== $request->getPort()) {
|
||||
return $fallback;
|
||||
}
|
||||
}
|
||||
$path = $parts['path'] ?? '';
|
||||
if (! str_starts_with($path, '/') || str_starts_with($path, '//')
|
||||
|| in_array($path, ['/login', '/logout', '/avaliar', '/avaliar/entrar'], true)) {
|
||||
return $fallback;
|
||||
}
|
||||
|
||||
return $path.(isset($parts['query']) ? '?'.$parts['query'] : '');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user