/** * @inheritdoc * @throws ExporterException */ public function export() { $this->validate(); foreach ($this->game->getEvents() as $event) { file_put_contents($this->path, $event->describe() . "\n", FILE_APPEND | LOCK_EX); } }
/** * @inheritdoc * @throws ExporterException */ public function export() { foreach ($this->game->getEvents() as $event) { if (strlen($event->describe()) > 1) { $this->command->climate->out($event->describe()); } else { // DEBUG -- If this happens something wasn't parsed properly var_dump($event); } } }
/** * @inheritdoc */ public function export() { $this->prepare(); foreach ($this->game->getEvents() as $event) { $filePath = $this->path . DIRECTORY_SEPARATOR . $this->getOption('nameFormat'); $filePath = str_replace('%EVENTTYPE%', $event->getType(), $filePath); if (!file_exists($filePath)) { // First write the column headers file_put_contents($filePath, implode(',', $this->getHeadersForEvent($event)) . "\n", FILE_APPEND | LOCK_EX); } file_put_contents($filePath, $this->getEventAsLine($event) . "\n", FILE_APPEND | LOCK_EX); } return true; }
/** * @param string $filename * * @return Game */ private function createGameWithInfo($filename) { // Temporarily disable xml errors since the file we're parsing is a bit of a mess libxml_use_internal_errors(true); $doc = new \DOMDocument(); $doc->loadHTMLFile($filename); // These contain all the info we need with a whole lot of extra whitespace to remove $v_text = preg_replace("/[^A-Za-z\\d]/", "", $doc->getElementById('Visitor')->textContent); $h_text = preg_replace("/[^A-Za-z\\d]/", "", $doc->getElementById('Home')->textContent); // Grab the home / away teams and scores if (preg_match_all(Game::RX_SCORETEAMS, $v_text, $matches_visitor)) { $away = new Team($matches_visitor[2][0]); $away_score = $matches_visitor[1][0]; } else { // DEBUG: Remove me later OK? var_dump($v_text); die; return false; } if (preg_match_all(Game::RX_SCORETEAMS, $h_text, $matches_home)) { $home = new Team($matches_home[2][0]); $home_score = $matches_home[1][0]; } else { // DEBUG: Remove me later OK? var_dump($h_text); die; return false; } // Generate the game ID based off of the filename $parts = explode(DIRECTORY_SEPARATOR, $filename); $season = $parts[count($parts) - 2]; $game_number = str_replace('.HTM', '', end($parts)); $game_id = $season . $game_number; $game = new Game($game_id); $game->setHomeTeam($home); $game->setAwayTeam($away); $game->setFinalScore($home_score, $away_score); $game->setSeason($season); // Get the attendence, start/end times and location /** @var \DOMNode $childNode */ foreach ($doc->getElementById('GameInfo')->childNodes as $childNode) { $value = trim(preg_replace('!\\s+!', ' ', $childNode->textContent)); $value = preg_replace('/[^a-zA-Z0-9\\s\\:]/', '', $value); if (mb_strlen($value) <= 2) { continue; } if (preg_match(Game::RX_DATE, $value, $matches)) { $game->date = $matches[1]; } else { if (preg_match(Game::RX_ATTEND, $value, $matches)) { $game->attendance = (int) $matches[1]; $game->venue = $matches[2]; } else { if (preg_match_all(Game::RX_ENDSTART, $value, $matches)) { $game->startTime = $matches[1][0]; $game->startTimeZone = $matches[2][0]; $game->endTime = $matches[1][1]; $game->endTimeZone = $matches[2][1]; } else { if ($value == "Final") { $game->wentOverTime = false; } } } } } libxml_use_internal_errors(false); return $game; }