Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
RangeValidator.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Ubiquity\contents\validation\validators\comparison
;
4
5
use Ajax\semantic\components\validation\CustomRule;
6
use
Ubiquity\contents\validation\validators\ValidatorHasNotNull
;
7
16
class
RangeValidator
extends
ValidatorHasNotNull
{
17
protected
$min
;
18
protected
$max
;
19
20
public
function
__construct
() {
21
$this->message =
"This value should be between `{min}` and `{max}`"
;
22
}
23
24
public
function
validate
(
$value
) {
25
parent::validate(
$value
);
26
if
($this->notNull !==
false
) {
27
return
$value
>= $this->min &&
$value
<=
$this->max
;
28
}
29
return
true
;
30
}
31
37
public
function
getParameters
(): array {
38
return [
'min'
,
'max'
,
'value'
];
39
}
40
46
public
function
asUI
(): array {
47
$rule = new CustomRule(
'range'
,
"function(v,minMax){ if(v) {[min,max]=minMax.split(',');v=parseInt(v,10);return v>=parseInt(min,10) && v<=parseInt(max,10);} return true;}"
, $this->_getMessage(), $this->min .
','
. $this->max);
48
return \array_merge_recursive(parent::asUI(), [
'rules'
=> [$rule]]);
49
}
50
}
51
Ubiquity\contents\validation\validators\ValidatorHasNotNull
Definition
ValidatorHasNotNull.php:8
Ubiquity\contents\validation\validators\Validator\$value
$value
Definition
Validator.php:15
Ubiquity\contents\validation\validators\comparison\RangeValidator
Check if a value is in a range.
Definition
RangeValidator.php:16
Ubiquity\contents\validation\validators\comparison\RangeValidator\getParameters
getParameters()
{{}\Ubiquity\contents\validation\validators\ValidatorInterfacegetParameters()}
Definition
RangeValidator.php:37
Ubiquity\contents\validation\validators\comparison\RangeValidator\__construct
__construct()
Definition
RangeValidator.php:20
Ubiquity\contents\validation\validators\comparison\RangeValidator\validate
validate($value)
Definition
RangeValidator.php:24
Ubiquity\contents\validation\validators\comparison\RangeValidator\$min
$min
Definition
RangeValidator.php:17
Ubiquity\contents\validation\validators\comparison\RangeValidator\$max
$max
Definition
RangeValidator.php:18
Ubiquity\contents\validation\validators\comparison\RangeValidator\asUI
asUI()
{}
Definition
RangeValidator.php:46
Ubiquity\contents\validation\validators\comparison
Definition
EqualsValidator.php:3
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity
src
Ubiquity
contents
validation
validators
comparison
RangeValidator.php
Generated on Sun Dec 10 2023 15:04:15 for
Ubiquity
by
doxygen
1.9.8