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