@@ -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); |
@@ -70,7 +72,9 @@ discard block |
||
| 70 | 72 | |
| 71 | 73 | protected function eval_getOper($rule,&$item) |
| 72 | 74 | { |
| 73 | - while ($rule[$item]==' ') $item++; |
|
| 75 | + while ($rule[$item]==' ') { |
|
| 76 | + $item++; |
|
| 77 | + } |
|
| 74 | 78 | switch ($rule[$item]) |
| 75 | 79 | { |
| 76 | 80 | case '<': |
@@ -97,12 +101,13 @@ discard block |
||
| 97 | 101 | |
| 98 | 102 | private function check_negate_first($rule,&$item) |
| 99 | 103 | { |
| 100 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 104 | + if ( $rule[$item] == '!') { |
|
| 105 | + // If '!' found, negate next expression. |
|
| 101 | 106 | { |
| 102 | 107 | $item++; |
| 103 | - return true; |
|
| 104 | 108 | } |
| 105 | - else |
|
| 109 | + return true; |
|
| 110 | + } else |
|
| 106 | 111 | { |
| 107 | 112 | return false; |
| 108 | 113 | } |
@@ -122,7 +127,10 @@ discard block |
||
| 122 | 127 | case '&': $retVal= ($val1 && $val2); break; |
| 123 | 128 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
| 124 | 129 | } |
| 125 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 130 | + if ($negate === true) { |
|
| 131 | + $retVal = ! $retVal; |
|
| 132 | + } |
|
| 133 | + // Inverse result if negate before expression |
|
| 126 | 134 | |
| 127 | 135 | return $retVal; |
| 128 | 136 | } |
@@ -143,10 +151,14 @@ discard block |
||
| 143 | 151 | list($type1,$val1) = $this->eval_getElement($rule,$item); |
| 144 | 152 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
| 145 | 153 | |
| 146 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 154 | + if ($item==strlen($rule)) { |
|
| 155 | + // If only element, return value, but only boolean |
|
| 147 | 156 | { |
| 148 | 157 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
| 149 | - if ($negate === true) $val1= ! $val1; |
|
| 158 | + } |
|
| 159 | + if ($negate === true) { |
|
| 160 | + $val1= ! $val1; |
|
| 161 | + } |
|
| 150 | 162 | return $val1; |
| 151 | 163 | } |
| 152 | 164 | |
@@ -155,31 +167,41 @@ discard block |
||
| 155 | 167 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
| 156 | 168 | |
| 157 | 169 | // Third element : number, string or () |
| 158 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 170 | + if ( $rule[$item] == '!') { |
|
| 171 | + // starts with a ! so evaluate whats next |
|
| 159 | 172 | { |
| 160 | 173 | $item++; |
| 161 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 174 | + } |
|
| 175 | + if ($typec != 1) { |
|
| 176 | + throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 177 | + } |
|
| 162 | 178 | $val2= ! $this->evaluation($rule,$item); |
| 163 | 179 | $type2=2; // result is a boolean |
| 164 | - } |
|
| 165 | - else |
|
| 180 | + } else |
|
| 166 | 181 | { |
| 167 | 182 | list($type2,$val2) = $this->eval_getElement($rule,$item); |
| 168 | 183 | } |
| 169 | 184 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
| 170 | 185 | |
| 171 | - if ($type1!=$type2) // cannot compare different types |
|
| 186 | + if ($type1!=$type2) { |
|
| 187 | + // cannot compare different types |
|
| 172 | 188 | { |
| 173 | 189 | throw new Exception("Cannot compare string & number : ".$rule); |
| 174 | 190 | } |
| 175 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 191 | + } |
|
| 192 | + if ($typec==1 && $type1 !=2) { |
|
| 193 | + // cannot use & or | with string/number |
|
| 176 | 194 | { |
| 177 | 195 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
| 178 | 196 | } |
| 197 | + } |
|
| 179 | 198 | |
| 180 | 199 | $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
| 181 | 200 | |
| 182 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 201 | + if ($item==strlen($rule)) { |
|
| 202 | + return $retVal; |
|
| 203 | + } |
|
| 204 | + // End of string : return evaluation |
|
| 183 | 205 | // check for logical operator : |
| 184 | 206 | switch ($rule[$item]) |
| 185 | 207 | { |
@@ -207,7 +229,9 @@ discard block |
||
| 207 | 229 | $rule2.=$rule[$item]; |
| 208 | 230 | $item++; |
| 209 | 231 | } |
| 210 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 232 | + if ($item == strlen ($rule)) { |
|
| 233 | + throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 234 | + } |
|
| 211 | 235 | $rule2.=$rule[$item]; |
| 212 | 236 | $item++; |
| 213 | 237 | continue; |
@@ -249,10 +273,12 @@ discard block |
||
| 249 | 273 | */ |
| 250 | 274 | public function eval_rule($rule,$oidList) |
| 251 | 275 | { |
| 252 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
| 276 | + if ($rule==null || $rule == '') { |
|
| 277 | + // Empty rule is always true |
|
| 253 | 278 | { |
| 254 | 279 | return true; |
| 255 | 280 | } |
| 281 | + } |
|
| 256 | 282 | $matches=array(); |
| 257 | 283 | while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
| 258 | 284 | { |
@@ -65,14 +65,15 @@ discard block |
||
| 65 | 65 | $start=$item; |
| 66 | 66 | $parenthesis_count=0; |
| 67 | 67 | while (($item < strlen($rule)) // Not end of string AND |
| 68 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
| 68 | + && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) { |
|
| 69 | + // Closing ')' or embeded () |
|
| 69 | 70 | { |
| 70 | 71 | if ($rule[$item] == '"' ) |
| 71 | 72 | { // pass through string |
| 72 | 73 | $item++; |
| 74 | + } |
|
| 73 | 75 | $item=$this->eval_getNext($rule,$item,'"'); |
| 74 | - } |
|
| 75 | - else{ |
|
| 76 | + } else{ |
|
| 76 | 77 | if ($rule[$item] == '(') |
| 77 | 78 | { |
| 78 | 79 | $parenthesis_count++; |
@@ -116,10 +117,12 @@ discard block |
||
| 116 | 117 | { |
| 117 | 118 | // function is : __function(param1,param2...) |
| 118 | 119 | $start=$item; |
| 119 | - while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
| 120 | + while (($item < strlen($rule)) && ($rule[$item] != '(' )) { |
|
| 121 | + // Not end of string AND not opening '(' |
|
| 120 | 122 | { |
| 121 | 123 | $item++; |
| 122 | 124 | } |
| 125 | + } |
|
| 123 | 126 | if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
| 124 | 127 | |
| 125 | 128 | // get parameters between parenthesis |