mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2025-02-04 16:51:14 +01:00
31 lines
643 B
PHP
31 lines
643 B
PHP
<?php
|
|
|
|
namespace Rakit\Validation\Rules;
|
|
|
|
use Rakit\Validation\Rule;
|
|
|
|
class Max extends Rule
|
|
{
|
|
|
|
protected $message = "The :attribute maximum is :max";
|
|
|
|
protected $fillable_params = ['max'];
|
|
|
|
public function check($value)
|
|
{
|
|
$this->requireParameters($this->fillable_params);
|
|
|
|
$max = (int) $this->parameter('max');
|
|
if (is_int($value)) {
|
|
return $value <= $max;
|
|
} elseif(is_string($value)) {
|
|
return mb_strlen($value, 'UTF-8') <= $max;
|
|
} elseif(is_array($value)) {
|
|
return count($value) <= $max;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|