ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
testDataFileIterator Class Reference
+ Inheritance diagram for testDataFileIterator:
+ Collaboration diagram for testDataFileIterator:

Public Member Functions

 __construct ($file)
 
 __destruct ()
 
 rewind ()
 
 valid ()
 
 key ()
 
 current ()
 
 next ()
 

Protected Attributes

 $file
 
 $key = 0
 
 $current
 

Private Member Functions

 _parseNextDataset ()
 
 _getcsv ($input, $delimiter, $enclosure)
 
 _parseDataValue ($dataValue)
 

Detailed Description

Definition at line 3 of file testDataFileIterator.php.

Constructor & Destructor Documentation

◆ __construct()

testDataFileIterator::__construct (   $file)

Definition at line 10 of file testDataFileIterator.php.

11 {
12 $this->file = fopen($file, 'r');
13 }

References $file.

◆ __destruct()

testDataFileIterator::__destruct ( )

Definition at line 15 of file testDataFileIterator.php.

16 {
17 fclose($this->file);
18 }

Member Function Documentation

◆ _getcsv()

testDataFileIterator::_getcsv (   $input,
  $delimiter,
  $enclosure 
)
private

Definition at line 69 of file testDataFileIterator.php.

70 {
71 if (function_exists('str_getcsv')) {
72 return str_getcsv($input, $delimiter, $enclosure);
73 }
74
75 $temp = fopen('php://memory', 'rw');
76 fwrite($temp, $input);
77 rewind($temp);
78 $data = fgetcsv($temp, strlen($input), $delimiter, $enclosure);
79 fclose($temp);
80
81 if ($data === false) {
82 $data = array(null);
83 }
84
85 return $data;
86 }

References $data, and rewind().

Referenced by _parseNextDataset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _parseDataValue()

testDataFileIterator::_parseDataValue (   $dataValue)
private

Definition at line 88 of file testDataFileIterator.php.

88 {
89 // discard any white space
90 $dataValue = trim($dataValue);
91 // test for the required datatype and convert accordingly
92 if (!is_numeric($dataValue)) {
93 if($dataValue == '') {
94 $dataValue = NULL;
95 } elseif($dataValue == '""') {
96 $dataValue = '';
97 } elseif(($dataValue[0] == '"') && ($dataValue[strlen($dataValue)-1] == '"')) {
98 $dataValue = substr($dataValue,1,-1);
99 } elseif(($dataValue[0] == '{') && ($dataValue[strlen($dataValue)-1] == '}')) {
100 $dataValue = explode(';',substr($dataValue,1,-1));
101 foreach($dataValue as &$dataRow) {
102 if (strpos($dataRow,'|') !== FALSE) {
103 $dataRow = explode('|',$dataRow);
104 foreach($dataRow as &$dataCell) {
105 $dataCell = $this->_parseDataValue($dataCell);
106 }
107 unset($dataCell);
108 } else {
109 $dataRow = $this->_parseDataValue($dataRow);
110 }
111 }
112 unset($dataRow);
113 } else {
114 switch (strtoupper($dataValue)) {
115 case 'NULL' : $dataValue = NULL; break;
116 case 'TRUE' : $dataValue = TRUE; break;
117 case 'FALSE' : $dataValue = FALSE; break;
118 }
119 }
120 } else {
121 if (strpos($dataValue,'.') !== FALSE) {
122 $dataValue = (float) $dataValue;
123 } else {
124 $dataValue = (int) $dataValue;
125 }
126 }
127
128 return $dataValue;
129 }

References _parseDataValue().

Referenced by _parseDataValue(), and _parseNextDataset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _parseNextDataset()

testDataFileIterator::_parseNextDataset ( )
private

Definition at line 48 of file testDataFileIterator.php.

49 {
50 // Read a line of test data from the file
51 do {
52 // Only take lines that contain test data and that aren't commented out
53 $testDataRow = trim(fgets($this->file));
54 } while (($testDataRow > '') && ($testDataRow{0} === '#'));
55
56 // Discard any comments at the end of the line
57 list($testData) = explode('//',$testDataRow);
58
59 // Split data into an array of individual values and a result
60 $dataSet = $this->_getcsv($testData, ',', "'");
61 foreach($dataSet as &$dataValue) {
62 $dataValue = $this->_parseDataValue($dataValue);
63 }
64 unset($dataValue);
65
66 return $dataSet;
67 }
_getcsv($input, $delimiter, $enclosure)

References _getcsv(), and _parseDataValue().

Referenced by next(), and rewind().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ current()

testDataFileIterator::current ( )

Definition at line 37 of file testDataFileIterator.php.

References $current.

Referenced by next(), and rewind().

+ Here is the caller graph for this function:

◆ key()

testDataFileIterator::key ( )

Definition at line 32 of file testDataFileIterator.php.

References $key.

Referenced by next(), and rewind().

+ Here is the caller graph for this function:

◆ next()

testDataFileIterator::next ( )

Definition at line 42 of file testDataFileIterator.php.

References _parseNextDataset(), current(), and key().

+ Here is the call graph for this function:

◆ rewind()

testDataFileIterator::rewind ( )

Definition at line 20 of file testDataFileIterator.php.

21 {
22 rewind($this->file);
23 $this->current = $this->_parseNextDataset();
24 $this->key = 0;
25 }

References _parseNextDataset(), current(), key(), and rewind().

Referenced by _getcsv(), and rewind().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ valid()

testDataFileIterator::valid ( )

Definition at line 27 of file testDataFileIterator.php.

28 {
29 return !feof($this->file);
30 }

Field Documentation

◆ $current

testDataFileIterator::$current
protected

Definition at line 8 of file testDataFileIterator.php.

Referenced by current().

◆ $file

testDataFileIterator::$file
protected

Definition at line 6 of file testDataFileIterator.php.

Referenced by __construct().

◆ $key

testDataFileIterator::$key = 0
protected

Definition at line 7 of file testDataFileIterator.php.

Referenced by key().


The documentation for this class was generated from the following file: