/** * @param string $line "[Date "1953.??.??"]" */ private function addMetaData($line) { if (strpos($line, ' ') === false) { throw new \Exception("Invalid metadata: " . $line); } list($key, $val) = explode(' ', $line, 2); $key = strtolower(trim($key, '[')); $val = trim($val, '"]'); switch ($key) { case 'event': $this->currentGame->setEvent($val); break; case 'site': $this->currentGame->setSite($val); break; case 'date': case 'eventdate': if (!$this->currentGame->getDate()) { $this->currentGame->setDate($val); } break; case 'round': $this->currentGame->setRound($val); break; case 'white': $this->currentGame->setWhite($val); break; case 'black': $this->currentGame->setBlack($val); break; case 'whiteelo': $this->currentGame->setWhiteElo($val); break; case 'blackelo': $this->currentGame->setBlackElo($val); break; case 'result': $this->currentGame->setResult($val); break; case 'eco': $this->currentGame->setEco($val); break; case 'plycount': $this->currentGame->setMovesCount($val); break; case 'fen': $this->currentGame->setFen($val); break; default: // Ignore others break; } }