Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\Repo\IO\LineReader Class Reference

LineReader allows iterating over the lines of a file. More...

+ Inheritance diagram for Wikibase\Repo\IO\LineReader:
+ Collaboration diagram for Wikibase\Repo\IO\LineReader:

Public Member Functions

 __construct ( $fileHandle, $canClose=true, $autoDispose=false)
 
 dispose ()
 Closes the underlying file handle if the $canClose parameter was given as true (the default) in the constructor.
 
 __destruct ()
 Destructor, calls dispose() if $autoDispose was set in the constructor.
 
 current ()
 Return the current line.
 
 next ()
 Reads the next line.
 
 key ()
 Return the current line number.
 
 valid ()
 Checks if current position is valid.
 
 rewind ()
 Sets the file pointer to the beginning of the file, if supported.
 

Private Attributes

 $fileHandle
 
 $canClose
 
 $autoDispose
 
 $current = null
 
 $line = 0
 

Detailed Description

LineReader allows iterating over the lines of a file.

Each line returned will contain the line separator character(s) and all whitespace. Concatenating all lines returned by the reader should result in the original file.

Author
Daniel Kinzler

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Repo\IO\LineReader::__construct (   $fileHandle,
  $canClose = true,
  $autoDispose = false 
)
Parameters
resource$fileHandleThe file to read from.
bool$canCloseWhether calling dispose() should close the fine handle.
bool$autoDisposeWhether to automatically call dispose() when reaching EOF or when this reader is destructed.
Exceptions
InvalidArgumentException

◆ __destruct()

Wikibase\Repo\IO\LineReader::__destruct ( )

Destructor, calls dispose() if $autoDispose was set in the constructor.

Member Function Documentation

◆ current()

Wikibase\Repo\IO\LineReader::current ( )

Return the current line.

See also
http://php.net/manual/en/iterator.current.php
Returns
string

◆ dispose()

Wikibase\Repo\IO\LineReader::dispose ( )

Closes the underlying file handle if the $canClose parameter was given as true (the default) in the constructor.

◆ key()

Wikibase\Repo\IO\LineReader::key ( )

Return the current line number.

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

◆ next()

Wikibase\Repo\IO\LineReader::next ( )

Reads the next line.

Use current() to get the line's content.

See also
http://php.net/manual/en/iterator.next.php

◆ rewind()

Wikibase\Repo\IO\LineReader::rewind ( )

Sets the file pointer to the beginning of the file, if supported.

Has no effect if this LineReader has already been disposed.

See also
http://php.net/manual/en/iterator.rewind.php
Returns
void Any returned value is ignored.

◆ valid()

Wikibase\Repo\IO\LineReader::valid ( )

Checks if current position is valid.

Returns true if and only if next() has been called at least once and the end of file has not yet been reached.

See also
http://php.net/manual/en/iterator.valid.php
Returns
boolean whether there is a current line

Member Data Documentation

◆ $autoDispose

Wikibase\Repo\IO\LineReader::$autoDispose
private

◆ $canClose

Wikibase\Repo\IO\LineReader::$canClose
private

◆ $current

Wikibase\Repo\IO\LineReader::$current = null
private

◆ $fileHandle

Wikibase\Repo\IO\LineReader::$fileHandle
private

◆ $line

Wikibase\Repo\IO\LineReader::$line = 0
private

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