@@ -60,14 +60,15 @@ discard block |
||
| 60 | 60 | $start=$item; |
| 61 | 61 | $parenthesis_count=0; |
| 62 | 62 | while (($item < strlen($rule)) // Not end of string AND |
| 63 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
| 63 | + && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) { |
|
| 64 | + // Closing ')' or embeded () |
|
| 64 | 65 | { |
| 65 | 66 | if ($rule[$item] == '"' ) |
| 66 | 67 | { // pass through string |
| 67 | 68 | $item++; |
| 69 | + } |
|
| 68 | 70 | $item=$this->eval_getNext($rule,$item,'"'); |
| 69 | - } |
|
| 70 | - else{ |
|
| 71 | + } else{ |
|
| 71 | 72 | if ($rule[$item] == '(') |
| 72 | 73 | { |
| 73 | 74 | $parenthesis_count++; |
@@ -95,7 +96,9 @@ discard block |
||
| 95 | 96 | { |
| 96 | 97 | throw new Exception("Early end of string ".$rule ." at " .$item ); |
| 97 | 98 | } |
| 98 | - while ($rule[$item]==' ') $item++; |
|
| 99 | + while ($rule[$item]==' ') { |
|
| 100 | + $item++; |
|
| 101 | + } |
|
| 99 | 102 | if (preg_match('/[0-9\.]/',$rule[$item])) |
| 100 | 103 | { // number |
| 101 | 104 | return $this->get_number($rule, $item); |
@@ -129,7 +132,9 @@ discard block |
||
| 129 | 132 | |
| 130 | 133 | protected function eval_getOper($rule,&$item) |
| 131 | 134 | { |
| 132 | - while ($rule[$item]==' ') $item++; |
|
| 135 | + while ($rule[$item]==' ') { |
|
| 136 | + $item++; |
|
| 137 | + } |
|
| 133 | 138 | switch ($rule[$item]) |
| 134 | 139 | { |
| 135 | 140 | case '<': |
@@ -156,12 +161,13 @@ discard block |
||
| 156 | 161 | |
| 157 | 162 | private function check_negate_first($rule,&$item) |
| 158 | 163 | { |
| 159 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 164 | + if ( $rule[$item] == '!') { |
|
| 165 | + // If '!' found, negate next expression. |
|
| 160 | 166 | { |
| 161 | 167 | $item++; |
| 162 | - return true; |
|
| 163 | 168 | } |
| 164 | - else |
|
| 169 | + return true; |
|
| 170 | + } else |
|
| 165 | 171 | { |
| 166 | 172 | return false; |
| 167 | 173 | } |
@@ -181,7 +187,10 @@ discard block |
||
| 181 | 187 | case '&': $retVal= ($val1 && $val2); break; |
| 182 | 188 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
| 183 | 189 | } |
| 184 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 190 | + if ($negate === true) { |
|
| 191 | + $retVal = ! $retVal; |
|
| 192 | + } |
|
| 193 | + // Inverse result if negate before expression |
|
| 185 | 194 | |
| 186 | 195 | return $retVal; |
| 187 | 196 | } |
@@ -202,10 +211,14 @@ discard block |
||
| 202 | 211 | list($type1,$val1) = $this->eval_getElement($rule,$item); |
| 203 | 212 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
| 204 | 213 | |
| 205 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 214 | + if ($item==strlen($rule)) { |
|
| 215 | + // If only element, return value, but only boolean |
|
| 206 | 216 | { |
| 207 | 217 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
| 208 | - if ($negate === true) $val1= ! $val1; |
|
| 218 | + } |
|
| 219 | + if ($negate === true) { |
|
| 220 | + $val1= ! $val1; |
|
| 221 | + } |
|
| 209 | 222 | return $val1; |
| 210 | 223 | } |
| 211 | 224 | |
@@ -214,31 +227,41 @@ discard block |
||
| 214 | 227 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
| 215 | 228 | |
| 216 | 229 | // Third element : number, string or () |
| 217 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 230 | + if ( $rule[$item] == '!') { |
|
| 231 | + // starts with a ! so evaluate whats next |
|
| 218 | 232 | { |
| 219 | 233 | $item++; |
| 220 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 234 | + } |
|
| 235 | + if ($typec != 1) { |
|
| 236 | + throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 237 | + } |
|
| 221 | 238 | $val2= ! $this->evaluation($rule,$item); |
| 222 | 239 | $type2=2; // result is a boolean |
| 223 | - } |
|
| 224 | - else |
|
| 240 | + } else |
|
| 225 | 241 | { |
| 226 | 242 | list($type2,$val2) = $this->eval_getElement($rule,$item); |
| 227 | 243 | } |
| 228 | 244 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
| 229 | 245 | |
| 230 | - if ($type1!=$type2) // cannot compare different types |
|
| 246 | + if ($type1!=$type2) { |
|
| 247 | + // cannot compare different types |
|
| 231 | 248 | { |
| 232 | 249 | throw new Exception("Cannot compare string & number : ".$rule); |
| 233 | 250 | } |
| 234 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 251 | + } |
|
| 252 | + if ($typec==1 && $type1 !=2) { |
|
| 253 | + // cannot use & or | with string/number |
|
| 235 | 254 | { |
| 236 | 255 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
| 237 | 256 | } |
| 257 | + } |
|
| 238 | 258 | |
| 239 | 259 | $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
| 240 | 260 | |
| 241 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 261 | + if ($item==strlen($rule)) { |
|
| 262 | + return $retVal; |
|
| 263 | + } |
|
| 264 | + // End of string : return evaluation |
|
| 242 | 265 | // check for logical operator : |
| 243 | 266 | switch ($rule[$item]) |
| 244 | 267 | { |
@@ -266,7 +289,9 @@ discard block |
||
| 266 | 289 | $rule2.=$rule[$item]; |
| 267 | 290 | $item++; |
| 268 | 291 | } |
| 269 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 292 | + if ($item == strlen ($rule)) { |
|
| 293 | + throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 294 | + } |
|
| 270 | 295 | $rule2.=$rule[$item]; |
| 271 | 296 | $item++; |
| 272 | 297 | continue; |
@@ -287,10 +312,12 @@ discard block |
||
| 287 | 312 | |
| 288 | 313 | public function eval_rule($rule,$oidList) |
| 289 | 314 | { |
| 290 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
| 315 | + if ($rule==null || $rule == '') { |
|
| 316 | + // Empty rule is always true |
|
| 291 | 317 | { |
| 292 | 318 | return true; |
| 293 | 319 | } |
| 320 | + } |
|
| 294 | 321 | $matches=array(); |
| 295 | 322 | while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
| 296 | 323 | { |