Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
RangeValidator.php
Go to the documentation of this file.
1<?php
2
4
5use Ajax\semantic\components\validation\CustomRule;
7
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
getParameters()
{{}\Ubiquity\contents\validation\validators\ValidatorInterfacegetParameters()}