Files
compras/app/Services/EvaluationNavigation.php
nala 48347e2d3a
tests / ci (push) Canceled after 0s
commit5
2026-10-30 10:55:18 +02:00

41 lines
1.4 KiB
PHP

<?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'] : '');
}
}