Moodle PHP Documentation 4.1
Moodle 4.1.19+ (Build: 20250711) (5f47dc23ffc)
Box\Spout\Reader\CSV\RowIterator Class Reference
Inheritance diagram for Box\Spout\Reader\CSV\RowIterator:
Box\Spout\Reader\IteratorInterface

Public Member Functions

 __construct ( $filePointer, OptionsManagerInterface $optionsManager, EncodingHelper $encodingHelper, InternalEntityFactory $entityFactory, GlobalFunctionsHelper $globalFunctionsHelper)
 
 current ()
 Return the current element from the buffer.
 
 end ()
 Cleans up what was created to iterate over the object.
 
 key ()
 Return the key of the current element.
 
 next ()
 Move forward to next element.
 
 rewind ()
 Rewind the Iterator to the first element.
 
 valid ()
 Checks if current position is valid.
 

Public Attributes

const MAX_READ_BYTES_PER_LINE = 0
 Value passed to fgetcsv.
 

Protected Member Functions

 getNextUTF8EncodedRow ()
 Returns the next row, converted if necessary to UTF-8.
 
 isEmptyLine ($lineData)
 
 readDataForNextRow ()
 
 rewindAndSkipBom ()
 This rewinds and skips the BOM if inserted at the beginning of the file by moving the file pointer after it, so that it is not read.
 
 shouldReadNextRow ($currentRowData)
 

Protected Attributes

string $encoding
 Encoding of the CSV file to be read.
 
Box Spout Common Helper EncodingHelper $encodingHelper
 Helper to work with different encodings.
 
Box Spout Reader CSV Creator InternalEntityFactory $entityFactory
 Factory to create entities.
 
string $fieldDelimiter
 Defines the character used to delimit fields (one character only)
 
string $fieldEnclosure
 Defines the character used to enclose fields (one character only)
 
resource $filePointer
 Pointer to the CSV file to read.
 
Box Spout Common Helper GlobalFunctionsHelper $globalFunctionsHelper
 Helper to work with global functions.
 
bool $hasReachedEndOfFile = false
 Indicates whether all rows have been read.
 
int $numReadRows = 0
 Number of read rows.
 
Row null $rowBuffer
 Buffer used to store the current row, while checking if there are more rows to read.
 
bool $shouldPreserveEmptyRows
 Whether empty rows should be returned or skipped.
 

Constructor & Destructor Documentation

◆ __construct()

Box\Spout\Reader\CSV\RowIterator::__construct ( $filePointer,
OptionsManagerInterface $optionsManager,
EncodingHelper $encodingHelper,
InternalEntityFactory $entityFactory,
GlobalFunctionsHelper $globalFunctionsHelper )
Parameters
resource$filePointerPointer to the CSV file to read
OptionsManagerInterface$optionsManager
EncodingHelper$encodingHelper
InternalEntityFactory$entityFactory
GlobalFunctionsHelper$globalFunctionsHelper

Member Function Documentation

◆ current()

Box\Spout\Reader\CSV\RowIterator::current ( )

Return the current element from the buffer.

See also
http://php.net/manual/en/iterator.current.php
Return values
Row|null

◆ end()

Box\Spout\Reader\CSV\RowIterator::end ( )

Cleans up what was created to iterate over the object.

Return values
void

Implements Box\Spout\Reader\IteratorInterface.

◆ getNextUTF8EncodedRow()

Box\Spout\Reader\CSV\RowIterator::getNextUTF8EncodedRow ( )
protected

Returns the next row, converted if necessary to UTF-8.

As fgetcsv() does not manage correctly encoding for non UTF-8 data, we remove manually whitespace with ltrim or rtrim (depending on the order of the bytes)

Exceptions
Box\Spout\Common\Exception\EncodingConversionExceptionIf unable to convert data to UTF-8
Return values
array|falseThe row for the current file pointer, encoded in UTF-8 or FALSE if nothing to read

◆ isEmptyLine()

Box\Spout\Reader\CSV\RowIterator::isEmptyLine ( $lineData)
protected
Parameters
array | bool$lineDataArray containing the cells value for the line
Return values
boolWhether the given line is empty

◆ key()

Box\Spout\Reader\CSV\RowIterator::key ( )

Return the key of the current element.

See also
http://php.net/manual/en/iterator.key.php
Return values
int

◆ next()

Box\Spout\Reader\CSV\RowIterator::next ( )

Move forward to next element.

Reads data for the next unprocessed row.

See also
http://php.net/manual/en/iterator.next.php
Exceptions
Box\Spout\Common\Exception\EncodingConversionExceptionIf unable to convert data to UTF-8
Return values
void

◆ readDataForNextRow()

Box\Spout\Reader\CSV\RowIterator::readDataForNextRow ( )
protected
Exceptions
Box\Spout\Common\Exception\EncodingConversionExceptionIf unable to convert data to UTF-8
Return values
void

◆ rewind()

Box\Spout\Reader\CSV\RowIterator::rewind ( )

Rewind the Iterator to the first element.

See also
http://php.net/manual/en/iterator.rewind.php
Return values
void

◆ rewindAndSkipBom()

Box\Spout\Reader\CSV\RowIterator::rewindAndSkipBom ( )
protected

This rewinds and skips the BOM if inserted at the beginning of the file by moving the file pointer after it, so that it is not read.

Return values
void

◆ shouldReadNextRow()

Box\Spout\Reader\CSV\RowIterator::shouldReadNextRow ( $currentRowData)
protected
Parameters
array | bool$currentRowData
Return values
boolWhether the data for the current row can be returned or if we need to keep reading

◆ valid()

Box\Spout\Reader\CSV\RowIterator::valid ( )

Checks if current position is valid.

See also
http://php.net/manual/en/iterator.valid.php
Return values
bool

Member Data Documentation

◆ MAX_READ_BYTES_PER_LINE

const Box\Spout\Reader\CSV\RowIterator::MAX_READ_BYTES_PER_LINE = 0

Value passed to fgetcsv.

0 means "unlimited" (slightly slower but accomodates for very long lines).


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