@@ -18,6 +18,16 @@ class FormPropertyLogicRule implements DataAwareRule, ValidationRule
18
18
'disable-block ' ,
19
19
];
20
20
21
+ private static $ conditionMappingData = null ;
22
+
23
+ public static function getConditionMapping ()
24
+ {
25
+ if (self ::$ conditionMappingData === null ) {
26
+ self ::$ conditionMappingData = json_decode (file_get_contents (resource_path ('data/open_filters.json ' )), true );
27
+ }
28
+ return self ::$ conditionMappingData ;
29
+ }
30
+
21
31
private $ isConditionCorrect = true ;
22
32
23
33
private $ isActionCorrect = true ;
@@ -30,16 +40,8 @@ class FormPropertyLogicRule implements DataAwareRule, ValidationRule
30
40
31
41
private $ operator = '' ;
32
42
33
- private $ conditionMapping = [];
34
-
35
- public function __construct ()
36
- {
37
- $ this ->conditionMapping = json_decode (file_get_contents (resource_path ('data/open_filters.json ' )), true );
38
- }
39
-
40
43
private function checkBaseCondition ($ condition )
41
44
{
42
-
43
45
if (!isset ($ condition ['value ' ])) {
44
46
$ this ->isConditionCorrect = false ;
45
47
$ this ->conditionErrors [] = 'missing condition body ' ;
@@ -80,21 +82,21 @@ private function checkBaseCondition($condition)
80
82
$ this ->operator = $ operator ;
81
83
$ value = $ condition ['value ' ]['value ' ];
82
84
83
- if (!isset ($ this -> conditionMapping [$ typeField ])) {
85
+ if (!isset (self :: getConditionMapping () [$ typeField ])) {
84
86
$ this ->isConditionCorrect = false ;
85
87
$ this ->conditionErrors [] = 'configuration not found for condition type ' ;
86
88
87
89
return ;
88
90
}
89
91
90
- if (!isset ($ this -> conditionMapping [$ typeField ]['comparators ' ][$ operator ])) {
92
+ if (!isset (self :: getConditionMapping () [$ typeField ]['comparators ' ][$ operator ])) {
91
93
$ this ->isConditionCorrect = false ;
92
94
$ this ->conditionErrors [] = 'configuration not found for condition operator ' ;
93
95
94
96
return ;
95
97
}
96
98
97
- $ type = $ this -> conditionMapping [$ typeField ]['comparators ' ][$ operator ]['expected_type ' ] ?? null ;
99
+ $ type = self :: getConditionMapping () [$ typeField ]['comparators ' ][$ operator ]['expected_type ' ] ?? null ;
98
100
99
101
if (is_array ($ type )) {
100
102
$ foundCorrectType = false ;
@@ -116,8 +118,8 @@ private function checkBaseCondition($condition)
116
118
117
119
private function valueHasCorrectType ($ type , $ value )
118
120
{
119
- if ($ type === 'string ' && isset ($ this -> conditionMapping [$ this ->field ['type ' ]]['comparators ' ][$ this ->operator ]['format ' ])) {
120
- $ format = $ this -> conditionMapping [$ this ->field ['type ' ]]['comparators ' ][$ this ->operator ]['format ' ];
121
+ if ($ type === 'string ' && isset (self :: getConditionMapping () [$ this ->field ['type ' ]]['comparators ' ][$ this ->operator ]['format ' ])) {
122
+ $ format = self :: getConditionMapping () [$ this ->field ['type ' ]]['comparators ' ][$ this ->operator ]['format ' ];
121
123
if ($ format ['type ' ] === 'regex ' ) {
122
124
try {
123
125
preg_match ('/ ' . $ value . '/ ' , '' );
0 commit comments