phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
Rule.php
Go to the documentation of this file.
1<?php
5
11class Rule implements \JsonSerializable{
15 private $type;
19 private $prompt;
20
24 private $value;
25
26 public function __construct($type,$prompt=NULL,$value=NULL){
27 $this->type=$type;
28 $this->prompt=$prompt;
29 $this->value=$value;
30 }
31
32 public function getType() {
33 return $this->type;
34 }
35
36 public function setType($type) {
37 $this->type=$type;
38 return $this;
39 }
40
41 public function getPrompt() {
42 return $this->prompt;
43 }
44
45 public function setPrompt($prompt) {
46 $this->prompt=$prompt;
47 return $this;
48 }
49
50 public function getValue() {
51 return $this->value;
52 }
53
54 public function setValue($value) {
55 $this->value=$value;
56 return $this;
57 }
58
59 #[\ReturnTypeWillChange]
60 public function jsonSerialize() {
61 $result= ["type"=>$this->type];
62 if(isset($this->prompt))
63 $result["prompt"]=$this->prompt;
64 if(isset($this->value))
65 $result["value"]=$this->value;
66 return $result;
67 }
68
75 public static function match($name,$prompt=NULL){
76 return new Rule("match[".$name."]",$prompt);
77 }
78
85 public static function different($name,$prompt=NULL){
86 return new Rule("different[".$name."]",$prompt);
87 }
88
96 public static function integer($min=NULL,$max=NULL,$prompt=NULL){
97 if(\is_int($min) && \is_int($max))
98 return new Rule("integer[{$min}..{$max}]",$prompt);
99 return new Rule("integer",$prompt);
100 }
101
102 public static function decimal($prompt=NULL){
103 return new Rule("decimal",$prompt);
104 }
105
106 public static function number($prompt=NULL){
107 return new Rule("number",$prompt);
108 }
109
110 public static function is($value,$prompt=NULL){
111 return new Rule("is[".$value."]",$prompt);
112 }
113
114 public static function isExactly($value,$prompt=NULL){
115 return new Rule("isExactly[".$value."]",$prompt);
116 }
117
118 public static function not($value,$prompt=NULL){
119 return new Rule("not[".$value."]",$prompt);
120 }
121
122 public static function notExactly($value,$prompt=NULL){
123 return new Rule("notExactly[".$value."]",$prompt);
124 }
125
126 public static function contains($value,$prompt=NULL){
127 return new Rule("contains[".$value."]",$prompt);
128 }
129
130 public static function containsExactly($value,$prompt=NULL){
131 return new Rule("containsExactly[".$value."]",$prompt);
132 }
133
134 public static function doesntContain($value,$prompt=NULL){
135 return new Rule("doesntContain[".$value."]",$prompt);
136 }
137
138 public static function doesntContainExactly($value,$prompt=NULL){
139 return new Rule("doesntContainExactly[".$value."]",$prompt);
140 }
141
142 public static function minCount($value,$prompt=NULL){
143 return new Rule("minCount[".$value."]",$prompt);
144 }
145
146 public static function maxCount($value,$prompt=NULL){
147 return new Rule("maxCount[".$value."]",$prompt);
148 }
149
150 public static function exactCount($value,$prompt=NULL){
151 return new Rule("exactCount[".$value."]",$prompt);
152 }
153
154 public static function email($prompt=NULL){
155 return new Rule("email",$prompt);
156 }
157
158 public static function url($prompt=NULL){
159 return new Rule("url",$prompt);
160 }
161
162 public static function regExp($value,$prompt=NULL){
163 return new Rule("regExp",$prompt,$value);
164 }
165
166 public static function custom($name,$jsFunction){
167 return "$.fn.form.settings.rules.".$name." =".$jsFunction ;
168 }
169
170 public static function ajax(JsUtils $js,$name,$url,$params,$jsCallback,$method="post",$parameters=[]){
171 $parameters=\array_merge(["async"=>false,"url"=>$url,"params"=>$params,"hasLoader"=>false,"jsCallback"=>$jsCallback,"dataType"=>"json","stopPropagation"=>false,"preventDefault"=>false,"responseElement"=>null],$parameters);
172 $ajax=new AjaxCall($method, $parameters);
173 return self::custom($name, "function(value,ruleValue){var result=true;".$ajax->compile($js)."return result;}");
174 }
175
176}
JQuery PHP library.
Definition JsUtils.php:23
static ajax(JsUtils $js, $name, $url, $params, $jsCallback, $method="post", $parameters=[])
Definition Rule.php:170
static match($name, $prompt=NULL)
A field should match the value of another validation field, for example to confirm passwords.
Definition Rule.php:75
static isExactly($value, $prompt=NULL)
Definition Rule.php:114
__construct($type, $prompt=NULL, $value=NULL)
Definition Rule.php:26
static custom($name, $jsFunction)
Definition Rule.php:166
static doesntContain($value, $prompt=NULL)
Definition Rule.php:134
static minCount($value, $prompt=NULL)
Definition Rule.php:142
static integer($min=NULL, $max=NULL, $prompt=NULL)
A field is an integer value, or matches an integer range.
Definition Rule.php:96
static regExp($value, $prompt=NULL)
Definition Rule.php:162
static notExactly($value, $prompt=NULL)
Definition Rule.php:122
static different($name, $prompt=NULL)
A field should be different than another specified field.
Definition Rule.php:85
static containsExactly($value, $prompt=NULL)
Definition Rule.php:130
static contains($value, $prompt=NULL)
Definition Rule.php:126
static maxCount($value, $prompt=NULL)
Definition Rule.php:146
static is($value, $prompt=NULL)
Definition Rule.php:110
static exactCount($value, $prompt=NULL)
Definition Rule.php:150
static doesntContainExactly($value, $prompt=NULL)
Definition Rule.php:138
static not($value, $prompt=NULL)
Definition Rule.php:118