Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

(no description)

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

Defines 1 class

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


Class: RowIterator  - X-Ref

Class RowIterator
Iterate over CSV rows.

__construct($filePointer,OptionsManagerInterface $optionsManager,EncodingHelper $encodingHelper,InternalEntityFactory $entityFactory,GlobalFunctionsHelper $globalFunctionsHelper)   X-Ref

param: resource $filePointer Pointer to the CSV file to read
param: OptionsManagerInterface $optionsManager
param: EncodingHelper $encodingHelper
param: InternalEntityFactory $entityFactory
param: GlobalFunctionsHelper $globalFunctionsHelper

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

return: void

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.

return: void

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

return: bool

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

return: void

readDataForNextRow()   X-Ref

return: void

shouldReadNextRow($currentRowData)   X-Ref

param: array|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|false The row for the current file pointer, encoded in UTF-8 or FALSE if nothing to read

isEmptyLine($lineData)   X-Ref

param: array|bool $lineData Array containing the cells value for the line
return: bool Whether the given line is empty

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

return: Row|null

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

return: int

end()   X-Ref
Cleans up what was created to iterate over the object.

return: void