forked from remko/wigit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParseable.php
executable file
·70 lines (52 loc) · 1.67 KB
/
Parseable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
abstract class Parseable{
protected $_arrData;
protected $_strName;
protected $_strError = '';
public function __construct(){
$this->_arrData = array();
$this->_strName = get_class($this);
}
abstract public function Parse($strText);
abstract public function ToHTML();
public function extraAction(){
}
protected function ParseAsTable($strText, $intExpectedColumns = -1){
// blank out the array
$this->_arrData = array();
// split the data
$arrData = explode(PHP_EOL,$strText);
// make sure we have the class name as the first element
if(trim($arrData[0]) != $this->_strName){
$this->AddError('Class was not found expected: ' . $this->_strName . ' found: ' . $arrData[0]);
return false;
}
// loop through the remaining results
for($i = 1; $i<count($arrData); $i++){
// make sure there is data to parse
if(strlen($arrData[$i])>0){
// split the string
$this->_arrData[$i-1] = explode('|', $arrData[$i]);
// remove the blank items
array_pop($this->_arrData[$i-1]);
array_shift($this->_arrData[$i-1]);
// check to see if we need to verify the columns
if($intExpectedColumns > 0){
// check
$intCount = count($this->_arrData[$i-1]);
if($intCount != $intExpectedColumns){
$this->AddError('Found wrong number of columns on line ' . $i . ' found ' . $intCount . ' but expected ' . $intExpectedColumns . '.');
return false;
}
}
}
}
return true;
}
public function AddError($strError){
$this->_strError .= $strError;
}
public function GetErrors(){
return $this->_strError;
}
}