Example #1
0
 /**
  * Parse a crash report
  *
  * @param string $source
  * @param boolean $mergeFleets
  *
  * @return Default_Model_CombatReport
  */
 public static function parse($source, $regexes, $settings)
 {
     $self = new self();
     $self->_regexes = $regexes;
     $self->_source = stristr($source, $regexes['start']);
     // check the CR
     if (false === $self->_source) {
         throw new Exception('Bad CR');
     }
     $self->_report = new Default_Model_CombatReport();
     $matches = array();
     if (preg_match('#' . $regexes["time"] . '#i', $self->_source, $matches)) {
         $self->_report->setTime(new DateTime($matches[3] . ":" . $matches[2] . ":" . $matches[1] . " " . $matches[4] . ":" . $matches[5] . ":" . $matches[6]));
     } else {
         throw new Exception('Bad CR');
     }
     $self->_source = substr($self->_source, strlen($matches[0]));
     while (preg_match('#' . $regexes["round"] . '#i', $self->_source)) {
         $self->_report->addRound($self->_parseRound());
     }
     $self->_parseResult();
     // check if we should merge multiple fleets of the same attacker or defender into one
     if ($settings['merge_fleets']) {
         $self->_mergeFleets();
     }
     return $self->_report;
 }