Code cleanup in parser
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
class DGTGameParser {
|
||||
|
||||
private $remoteUrl;
|
||||
|
@@ -1,8 +1,5 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 'on');
|
||||
|
||||
class FenParser0x88
|
||||
{
|
||||
private $fen;
|
||||
@@ -1278,7 +1275,7 @@ class FenParser0x88
|
||||
function getFen()
|
||||
{
|
||||
if (!$this->fen) {
|
||||
$this->fen = $this->setNewFen();
|
||||
$this->fen = $this->getNewFen();
|
||||
}
|
||||
return $this->fen;
|
||||
}
|
||||
@@ -1351,7 +1348,7 @@ class FenParser0x88
|
||||
|
||||
}
|
||||
|
||||
function setNewFen()
|
||||
private function getNewFen()
|
||||
{
|
||||
$board = $this->cache['board'];
|
||||
$fen = '';
|
||||
|
@@ -6,7 +6,6 @@ class GameParser {
|
||||
private $game;
|
||||
private $fen;
|
||||
|
||||
|
||||
public function __construct(){
|
||||
$this->moveParser = new FenParser0x88();
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ class PgnGameParser{
|
||||
$ret = array(
|
||||
CHESS_JSON::GAME_METADATA=>array()
|
||||
);
|
||||
// TODO set lastmoves property by reading last 3-4 moves in moves array
|
||||
$lines = explode("\n", $this->pgnGame);
|
||||
foreach($lines as $line){
|
||||
$line = trim($line);
|
||||
|
@@ -6,19 +6,22 @@ class PgnParser
|
||||
private $pgnFile;
|
||||
private $pgnContent;
|
||||
private $pgnGames;
|
||||
private $games;
|
||||
private $gameParser;
|
||||
private $pgnGameParser;
|
||||
private $_fullParsing = true;
|
||||
|
||||
public function __construct($pgnFile = "")
|
||||
public function __construct($pgnFile = "", $fullParsing =true)
|
||||
{
|
||||
if ($pgnFile) {
|
||||
$this->pgnFile = $pgnFile;
|
||||
}
|
||||
$this->_fullParsing = $fullParsing;
|
||||
$this->gameParser = new GameParser();
|
||||
$this->pgnGameParser = new PgnGameParser();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function setPgnContent($content)
|
||||
{
|
||||
$this->pgnContent = $content;
|
||||
@@ -65,9 +68,9 @@ class PgnParser
|
||||
return json_encode($this->getGames());
|
||||
}
|
||||
|
||||
private function isLazy()
|
||||
private function fullParsing()
|
||||
{
|
||||
return false;
|
||||
return $this->_fullParsing;
|
||||
}
|
||||
|
||||
public function getUnparsedGames()
|
||||
@@ -107,7 +110,7 @@ class PgnParser
|
||||
private function getParsedGame($unParsedGame){
|
||||
$this->pgnGameParser->setPgn($unParsedGame);
|
||||
$ret = $this->pgnGameParser->getParsedData();
|
||||
if (!$this->isLazy()) {
|
||||
if ($this->fullParsing()) {
|
||||
$ret = $this->gameParser->getParsedGame($ret);
|
||||
}
|
||||
return $ret;
|
||||
|
Reference in New Issue
Block a user