Exemplo n.º 1
0
 function parseFile($files)
 {
     $rb = new RuleBase();
     if (is_string($files)) {
         $files = array($files);
     }
     foreach ($files as $file) {
         if (!file_exists($file)) {
             print "File {$file} does not exist!";
             continue;
         }
         $fh = fopen($file, "r");
         $ruleInfo = array();
         $rawRule = '';
         while (!feof($fh)) {
             $line = fgets($fh);
             if (preg_match('/^rule "{0,1}([^"]*)"{0,1}\\s+(.*)$/', $line, $matches)) {
                 if (trim($rawRule) != '') {
                     $rb->addRule($this->buildRule($ruleInfo, $rawRule));
                 }
                 $ruleInfo = $matches;
                 $rawRule = '';
             } else {
                 if (feof($fh)) {
                     $rb->addRule($this->buildRule($ruleInfo, $rawRule . $line));
                 } else {
                     $rawRule .= $line;
                 }
             }
         }
         fclose($fh);
     }
     return $rb;
 }
 /**
  * @return int
  */
 public function getSeconds()
 {
     return rand($this->min_sleep_seconds, parent::getSeconds());
 }