Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 402 and 403]

(no description)

File Size: 218 lines (7 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

RowIterator:: (11 methods):
  __construct()
  rewind()
  valid()
  next()
  current()
  key()
  rewindAndSkipBom()
  readDataForNextRow()
  shouldReadNextRow()
  getNextUTF8EncodedRow()
  isEmptyLine()


Class: RowIterator  - X-Ref

Iterate over CSV rows.

__construct($filePointer,Options $options,EncodingHelper $encodingHelper)   X-Ref

param: resource $filePointer Pointer to the CSV file to read

rewind()   X-Ref
Rewind the Iterator to the first element.


valid()   X-Ref
Checks if current position is valid.


next()   X-Ref
Move forward to next element. Reads data for the next unprocessed row.


current()   X-Ref
Return the current element from the buffer.


key()   X-Ref
Return the key of the current element.


rewindAndSkipBom()   X-Ref
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.


readDataForNextRow()   X-Ref


shouldReadNextRow($currentRowData)   X-Ref

param: array<int, null|string>|bool $currentRowData
return: bool Whether the data for the current row can be returned or if we need to keep reading

getNextUTF8EncodedRow()   X-Ref
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).

return: array<int, null|string>|false The row for the current file pointer, encoded in UTF-8 or FALSE if nothing to read

isEmptyLine($lineData)   X-Ref

param: array<int, null|string>|bool $lineData Array containing the cells value for the line
return: bool Whether the given line is empty