@@ -71,11 +71,13 @@ discard block |
||
| 71 | 71 | $start=$item; |
| 72 | 72 | $parenthesisCount=0; |
| 73 | 73 | while (($item < strlen($rule)) // Not end of string AND |
| 74 | - && ( ($rule[$item] != ')' ) || $parenthesisCount > 0) ) // Closing ')' or embeded () |
|
| 74 | + && ( ($rule[$item] != ')' ) || $parenthesisCount > 0) ) { |
|
| 75 | + // Closing ')' or embeded () |
|
| 75 | 76 | { |
| 76 | 77 | if ($rule[$item] == '"' ) |
| 77 | 78 | { // pass through string |
| 78 | 79 | $item++; |
| 80 | + } |
|
| 79 | 81 | $item=$this->eval_getNext($rule,$item,'"'); |
| 80 | 82 | continue; |
| 81 | 83 | } |
@@ -121,10 +123,12 @@ discard block |
||
| 121 | 123 | { |
| 122 | 124 | // function is : __function(param1,param2...) |
| 123 | 125 | $start=$item; |
| 124 | - while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
| 126 | + while (($item < strlen($rule)) && ($rule[$item] != '(' )) { |
|
| 127 | + // Not end of string AND not opening '(' |
|
| 125 | 128 | { |
| 126 | 129 | $item++; |
| 127 | 130 | } |
| 131 | + } |
|
| 128 | 132 | if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
| 129 | 133 | |
| 130 | 134 | // get parameters between parenthesis |
@@ -167,12 +171,13 @@ discard block |
||
| 167 | 171 | */ |
| 168 | 172 | private function check_negate_first(string $rule,int &$item) |
| 169 | 173 | { |
| 170 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 174 | + if ( $rule[$item] == '!') { |
|
| 175 | + // If '!' found, negate next expression. |
|
| 171 | 176 | { |
| 172 | 177 | $item++; |
| 173 | - return true; |
|
| 174 | 178 | } |
| 175 | - else |
|
| 179 | + return true; |
|
| 180 | + } else |
|
| 176 | 181 | { |
| 177 | 182 | return false; |
| 178 | 183 | } |
@@ -199,7 +204,9 @@ discard block |
||
| 199 | 204 | $rule2.=$rule[$item]; |
| 200 | 205 | $item++; |
| 201 | 206 | } |
| 202 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 207 | + if ($item == strlen ($rule)) { |
|
| 208 | + throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 209 | + } |
|
| 203 | 210 | $rule2.=$rule[$item]; |
| 204 | 211 | $item++; |
| 205 | 212 | continue; |
@@ -32,7 +32,9 @@ discard block |
||
| 32 | 32 | { |
| 33 | 33 | throw new Exception("Early end of string ".$rule ." at " .$item ); |
| 34 | 34 | } |
| 35 | - while ($rule[$item]==' ') $item++; |
|
| 35 | + while ($rule[$item]==' ') { |
|
| 36 | + $item++; |
|
| 37 | + } |
|
| 36 | 38 | if (preg_match('/[\-0-9\.]/',$rule[$item])) |
| 37 | 39 | { // number |
| 38 | 40 | return $this->get_number($rule, $item); |
@@ -56,7 +58,9 @@ discard block |
||
| 56 | 58 | |
| 57 | 59 | protected function eval_getOper($rule,&$item) |
| 58 | 60 | { |
| 59 | - while ($rule[$item]==' ') $item++; |
|
| 61 | + while ($rule[$item]==' ') { |
|
| 62 | + $item++; |
|
| 63 | + } |
|
| 60 | 64 | switch ($rule[$item]) |
| 61 | 65 | { |
| 62 | 66 | case '<': |
@@ -95,7 +99,10 @@ discard block |
||
| 95 | 99 | case '&': $retVal= ($val1 && $val2); break; |
| 96 | 100 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
| 97 | 101 | } |
| 98 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 102 | + if ($negate === true) { |
|
| 103 | + $retVal = ! $retVal; |
|
| 104 | + } |
|
| 105 | + // Inverse result if negate before expression |
|
| 99 | 106 | |
| 100 | 107 | return $retVal; |
| 101 | 108 | } |
@@ -116,10 +123,14 @@ discard block |
||
| 116 | 123 | list($type1,$val1) = $this->eval_getElement($rule,$item); |
| 117 | 124 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
| 118 | 125 | |
| 119 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 126 | + if ($item==strlen($rule)) { |
|
| 127 | + // If only element, return value, but only boolean |
|
| 120 | 128 | { |
| 121 | 129 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
| 122 | - if ($negate === true) $val1= ! $val1; |
|
| 130 | + } |
|
| 131 | + if ($negate === true) { |
|
| 132 | + $val1= ! $val1; |
|
| 133 | + } |
|
| 123 | 134 | return $val1; |
| 124 | 135 | } |
| 125 | 136 | |
@@ -128,31 +139,41 @@ discard block |
||
| 128 | 139 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
| 129 | 140 | |
| 130 | 141 | // Third element : number, string or () |
| 131 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 142 | + if ( $rule[$item] == '!') { |
|
| 143 | + // starts with a ! so evaluate whats next |
|
| 132 | 144 | { |
| 133 | 145 | $item++; |
| 134 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 146 | + } |
|
| 147 | + if ($typec != 1) { |
|
| 148 | + throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 149 | + } |
|
| 135 | 150 | $val2= ! $this->evaluation($rule,$item); |
| 136 | 151 | $type2=2; // result is a boolean |
| 137 | - } |
|
| 138 | - else |
|
| 152 | + } else |
|
| 139 | 153 | { |
| 140 | 154 | list($type2,$val2) = $this->eval_getElement($rule,$item); |
| 141 | 155 | } |
| 142 | 156 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
| 143 | 157 | |
| 144 | - if ($type1!=$type2) // cannot compare different types |
|
| 158 | + if ($type1!=$type2) { |
|
| 159 | + // cannot compare different types |
|
| 145 | 160 | { |
| 146 | 161 | throw new Exception("Cannot compare string & number : ".$rule); |
| 147 | 162 | } |
| 148 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 163 | + } |
|
| 164 | + if ($typec==1 && $type1 !=2) { |
|
| 165 | + // cannot use & or | with string/number |
|
| 149 | 166 | { |
| 150 | 167 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
| 151 | 168 | } |
| 169 | + } |
|
| 152 | 170 | |
| 153 | 171 | $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
| 154 | 172 | |
| 155 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 173 | + if ($item==strlen($rule)) { |
|
| 174 | + return $retVal; |
|
| 175 | + } |
|
| 176 | + // End of string : return evaluation |
|
| 156 | 177 | // check for logical operator : |
| 157 | 178 | switch ($rule[$item]) |
| 158 | 179 | { |
@@ -191,10 +212,12 @@ discard block |
||
| 191 | 212 | */ |
| 192 | 213 | public function eval_rule($rule,$oidList) |
| 193 | 214 | { |
| 194 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
| 215 | + if ($rule==null || $rule == '') { |
|
| 216 | + // Empty rule is always true |
|
| 195 | 217 | { |
| 196 | 218 | return true; |
| 197 | 219 | } |
| 220 | + } |
|
| 198 | 221 | $matches=array(); |
| 199 | 222 | while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
| 200 | 223 | { |