Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
IdValidator.php
Go to the documentation of this file.
1<?php
2
4
10 protected $autoinc;
11 public function __construct(){
12 parent::__construct();
13 $this->message=array_merge($this->message,[
14 'positive'=>'This value must be positive',
15 'type'=>'This value must be an integer'
16 ]);
17 }
18
19 public function validate($value) {
20 if (!parent::validate($value)) {
21 return false;
22 }
23 if($value!=(int)$value){
24 $this->violation='type';
25 return false;
26 }
27 if($value<=0){
28 $this->violation='positive';
29 return false;
30 }
31 return true;
32 }
33
38 public function getParameters(): array {
39 return ['value'];
40 }
45 protected function setParams(array $params) {
46 parent::setParams($params);
47 if($this->autoinc===true){
48 $this->notNull=false;
49 }
50 }
51
57 public function asUI(): array {
58 $rules[] = ['type' => 'regExp', 'prompt' => $this->_getMessage()['positive'], 'value' => '^[1-9]+$|^$'];
59 return \array_merge_recursive(parent::asUI () , ['inputType'=>'number','rules' => $rules]);
60 }
61}
62
Validate int identifiers (notNull positive integer).
getParameters()
{}\Ubiquity\contents\validation\validators\ValidatorInterfacegetParameters()