|
4 | 4 | use App\Models\ServiceApplication; |
5 | 5 | use Illuminate\Support\Collection; |
6 | 6 |
|
| 7 | +function isValidDomainUrl(string $url): bool |
| 8 | +{ |
| 9 | + $components = parse_url($url); |
| 10 | + |
| 11 | + if ($components === false) { |
| 12 | + return false; |
| 13 | + } |
| 14 | + |
| 15 | + $scheme = $components['scheme'] ?? ''; |
| 16 | + $host = $components['host'] ?? ''; |
| 17 | + |
| 18 | + if (! in_array(strtolower($scheme), ['http', 'https'], true) || $host === '') { |
| 19 | + return false; |
| 20 | + } |
| 21 | + |
| 22 | + $urlToValidate = $scheme.'://'; |
| 23 | + |
| 24 | + if (isset($components['user'])) { |
| 25 | + $urlToValidate .= $components['user']; |
| 26 | + |
| 27 | + if (isset($components['pass'])) { |
| 28 | + $urlToValidate .= ':'.$components['pass']; |
| 29 | + } |
| 30 | + |
| 31 | + $urlToValidate .= '@'; |
| 32 | + } |
| 33 | + |
| 34 | + $urlToValidate .= str_replace('_', '-', $host); |
| 35 | + |
| 36 | + if (isset($components['port'])) { |
| 37 | + $urlToValidate .= ':'.$components['port']; |
| 38 | + } |
| 39 | + |
| 40 | + if (isset($components['path'])) { |
| 41 | + $urlToValidate .= $components['path']; |
| 42 | + } |
| 43 | + |
| 44 | + if (isset($components['query'])) { |
| 45 | + $urlToValidate .= '?'.$components['query']; |
| 46 | + } |
| 47 | + |
| 48 | + if (isset($components['fragment'])) { |
| 49 | + $urlToValidate .= '#'.$components['fragment']; |
| 50 | + } |
| 51 | + |
| 52 | + return filter_var($urlToValidate, FILTER_VALIDATE_URL) !== false; |
| 53 | +} |
| 54 | + |
7 | 55 | function checkDomainUsage(ServiceApplication|Application|null $resource = null, ?string $domain = null) |
8 | 56 | { |
9 | 57 | $conflicts = []; |
|
0 commit comments