mirror of
https://github.com/pelican-dev/panel.git
synced 2025-06-15 15:11:08 +02:00
Allow port rule to be optional
This commit is contained in:
parent
4273880126
commit
c45e4edcf6
@ -8,26 +8,30 @@ use Illuminate\Contracts\Validation\ValidationRule;
|
|||||||
|
|
||||||
class Port implements ValidationRule
|
class Port implements ValidationRule
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Run the validation rule.
|
|
||||||
*
|
|
||||||
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
|
||||||
*/
|
|
||||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||||
{
|
{
|
||||||
|
// Allow port to be optional
|
||||||
|
if (empty($value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Require port to be a number
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
$fail('The :attribute must be numeric.');
|
$fail('The :attribute must be numeric.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Require port to be an integer
|
||||||
$value = intval($value);
|
$value = intval($value);
|
||||||
if (floatval($value) !== (float) $value) {
|
if (floatval($value) !== (float) $value) {
|
||||||
$fail('The :attribute must be an integer.');
|
$fail('The :attribute must be an integer.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Require minimum valid port
|
||||||
if ($value <= Endpoint::PORT_FLOOR) {
|
if ($value <= Endpoint::PORT_FLOOR) {
|
||||||
$fail('The :attribute must be greater than 1024.');
|
$fail('The :attribute must be greater than 1024.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Require maximum valid port
|
||||||
if ($value > Endpoint::PORT_CEIL) {
|
if ($value > Endpoint::PORT_CEIL) {
|
||||||
$fail('The :attribute must be less than 65535.');
|
$fail('The :attribute must be less than 65535.');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user