1
1
<?php
2
2
namespace Ajax \semantic \components \validation ;
3
+
3
4
use Ajax \JsUtils ;
4
5
use Ajax \service \JArray ;
5
6
6
7
/**
8
+ *
7
9
* @author jc
8
10
* @version 1.001
9
- * Generates a JSON field validator
11
+ * Generates a JSON field validator
10
12
*/
11
- class FieldValidation implements \JsonSerializable{
13
+ class FieldValidation implements \JsonSerializable {
14
+
12
15
/**
16
+ *
13
17
* @var string
14
18
*/
15
- protected $ identifier ;
19
+ protected $ identifier ;
20
+
16
21
/**
22
+ *
17
23
* @var array array of Rules
18
24
*/
19
25
protected $ rules ;
26
+
20
27
/**
28
+ *
21
29
* @var array array of custom rules
22
30
*/
23
31
protected $ customRules ;
24
32
25
- protected $ hasCustomRules= false ;
33
+ protected $ hasCustomRules = false ;
26
34
27
35
/**
36
+ *
28
37
* @var string
29
38
*/
30
39
protected $ depends ;
31
40
32
41
protected $ optional ;
33
42
34
- public function __construct ($ identifier ){
35
- $ this ->identifier = $ identifier ;
36
- $ this ->rules = [];
43
+ public function __construct ($ identifier ) {
44
+ $ this ->identifier = $ identifier ;
45
+ $ this ->rules = [];
37
46
}
38
47
39
48
public function getIdentifier () {
40
49
return $ this ->identifier ;
41
50
}
42
51
43
52
public function setIdentifier ($ identifier ) {
44
- $ this ->identifier = $ identifier ;
53
+ $ this ->identifier = $ identifier ;
45
54
return $ this ;
46
55
}
47
56
@@ -50,57 +59,61 @@ public function getRules() {
50
59
}
51
60
52
61
/**
62
+ *
53
63
* @param string|Rule|array $type
54
64
* @param string $prompt
55
65
* @param string $value
56
66
* @return Rule
57
67
*/
58
- public function addRule ($ type ,$ prompt= NULL ,$ value= NULL ){
59
- if ($ type instanceof Rule) {
68
+ public function addRule ($ type , $ prompt = NULL , $ value = NULL ) {
69
+ if ($ type instanceof Rule) {
60
70
$ rule = $ type ;
61
- if ($ type instanceof CustomRule){
62
- $ this ->customRules []= $ type ;
63
- $ this ->hasCustomRules = true ;
71
+ if ($ type instanceof CustomRule) {
72
+ $ this ->customRules [] = $ type ;
73
+ $ this ->hasCustomRules = true ;
64
74
}
65
- }elseif (\is_array ($ type )){
66
- $ value= JArray::getValue ($ type , "value " , 2 );
67
- $ prompt= JArray::getValue ($ type , "prompt " , 1 );
68
- $ type= JArray::getValue ($ type , "type " , 0 );
69
- $ rule= new Rule ($ type ,$ prompt ,$ value );
70
- }else {
75
+ } elseif (\is_array ($ type )) {
76
+ $ value = JArray::getValue ($ type , "value " , 2 );
77
+ $ prompt = JArray::getValue ($ type , "prompt " , 1 );
78
+ $ type = JArray::getValue ($ type , "type " , 0 );
79
+ $ rule = new Rule ($ type , $ prompt , $ value );
80
+ } else {
71
81
$ rule = new Rule ($ type , $ prompt , $ value );
72
82
}
73
- $ this ->rules []= $ rule ;
83
+ $ this ->rules [] = $ rule ;
74
84
return $ rule ;
75
85
}
76
86
77
- public function jsonSerialize (){
78
- $ result =["identifier " =>$ this ->identifier ,"rules " =>$ this ->rules ];
79
- if ($ this ->optional ){
80
- $ result ["optional " ]=true ;
87
+ # [\ReturnTypeWillChange]
88
+ public function jsonSerialize () {
89
+ $ result = [
90
+ "identifier " => $ this ->identifier ,
91
+ "rules " => $ this ->rules
92
+ ];
93
+ if ($ this ->optional ) {
94
+ $ result ["optional " ] = true ;
81
95
}
82
- if (isset ($ this ->depends )){
83
- $ result ["depends " ]= $ this ->depends ;
96
+ if (isset ($ this ->depends )) {
97
+ $ result ["depends " ] = $ this ->depends ;
84
98
}
85
99
return $ result ;
86
100
}
87
101
88
102
public function setDepends ($ depends ) {
89
- $ this ->depends = $ depends ;
103
+ $ this ->depends = $ depends ;
90
104
return $ this ;
91
105
}
92
106
93
107
public function setOptional ($ optional ) {
94
- $ this ->optional = $ optional ;
108
+ $ this ->optional = $ optional ;
95
109
return $ this ;
96
110
}
97
111
98
- public function compile (JsUtils $ js ){
99
- if ($ this ->hasCustomRules ) {
112
+ public function compile (JsUtils $ js ) {
113
+ if ($ this ->hasCustomRules ) {
100
114
foreach ($ this ->customRules as $ rule ) {
101
115
$ rule ->compile ($ js );
102
116
}
103
117
}
104
118
}
105
-
106
119
}
0 commit comments