mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-13 12:14:28 +00:00
chore: prepare for PR
This commit is contained in:
1 parent
8a5ccd6323
commit
839635e9e8
7 files changed
+202
-20
No files matched your search
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
class ValidServerIp implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Accepts a valid IPv4 address, IPv6 address, or RFC 1123 hostname.
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$trimmed = trim($value);
|
||||
|
||||
if (filter_var($trimmed, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (filter_var($trimmed, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Delegate hostname validation to ValidHostname
|
||||
$hostnameRule = new ValidHostname;
|
||||
$failed = false;
|
||||
$hostnameRule->validate($attribute, $trimmed, function () use (&$failed) {
|
||||
$failed = true;
|
||||
});
|
||||
|
||||
if ($failed) {
|
||||
$fail('The :attribute must be a valid IPv4 address, IPv6 address, or hostname.');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user