mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 01:44:45 +02:00
Add port validation rule for #68
This commit is contained in:
parent
53a5ff6e6d
commit
ae399f9bad
34
app/Rules/Port.php
Normal file
34
app/Rules/Port.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\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
|
||||
{
|
||||
if (!is_numeric($value)) {
|
||||
$fail('The :attribute must be numeric.');
|
||||
}
|
||||
|
||||
$value = intval($value);
|
||||
if (floatval($value) !== (float) $value) {
|
||||
$fail('The :attribute must be an integer.');
|
||||
}
|
||||
|
||||
if ($value < 0) {
|
||||
$fail('The :attribute must be greater or equal to 0.');
|
||||
}
|
||||
|
||||
if ($value > 65535) {
|
||||
$fail('The :attribute must be less or equal to 65535.');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user