Erebot  latest
A modular IRC bot for PHP 7.0+
Erebot\LineIO Class Reference

A class that provides a line-by-line reader. More...

Public Member Functions

 __construct ($eol, $socket=null)
 
 getEOL ()
 
 getSocket ()
 
 inReadQueue ()
 
 inWriteQueue ()
 
 pop ()
 
 push ($line)
 
 read ()
 
 setEOL ($eol)
 
 setSocket ($socket)
 
 write ()
 

Public Attributes

const EOL_ANY = null
 Universal line-ending mode (compatible with Windows, Mac and *nix).
 
const EOL_NEW_MAC = "\n"
 New MacOS line-ending (MacOS > 9).
 
const EOL_OLD_MAC = "\r"
 Old MacOS line-ending (MacOS <= 9).
 
const EOL_UNIX = "\n"
 Unix line-ending.
 
const EOL_WIN = "\r\n"
 Windows line-ending.
 

Protected Member Functions

 getLine ()
 

Protected Attributes

 $eol
 Line-ending mode in use.
 
 $incomingData
 A raw buffer for incoming data.
 
 $rcvQueue
 A FIFO queue for incoming messages.
 
 $sndQueue
 A FIFO queue for outgoing messages.
 
 $socket
 The underlying socket, represented as a stream.
 

Detailed Description

A class that provides a line-by-line reader.

Using this class, it is possible to read messages one line at a time simply by specifying the End-Of-Line (EOL) style in use by the protocol.

Definition at line 31 of file LineIO.php.

Constructor & Destructor Documentation

Erebot\LineIO::__construct (   $eol,
  $socket = null 
)

Constructs a new line-by-line reader.

Parameters
opaque$eolThe type of line-endings to accept. This may be one of Erebot::LineIO::EOL_WIN, Erebot::LineIO::EOL_OLD_MAC, Erebot::LineIO::EOL_NEW_MAC, Erebot::LineIO::EOL_UNIX or Erebot::LineIO::EOL_ANY.
resource$socket(optional) The socket to operate on.
Warning
Even though the $socket argument is optional here, you must still provide one (using the setSocket() method) before calling any of this object's methods. Failure to do so may result in unpredictable results.

Definition at line 85 of file LineIO.php.

Member Function Documentation

Erebot\LineIO::getEOL ( )

Returns the End-Of-Line (EOL) style currently used.

Return values
opaqueEOL style currently in use.

Definition at line 157 of file LineIO.php.

Erebot\LineIO::getLine ( )
protected

Retrieves a single line of text from the incoming buffer and puts it in the incoming FIFO.

Return values
trueWhether a line could be fetched from the buffer.
false... or not.
Note
Lines fetched by this method are always UTF-8 encoded.

Definition at line 175 of file LineIO.php.

Erebot\LineIO::getSocket ( )

Returns the socket associated with this reader.

Return values
resourceSocket associated with this reader, as set during this object's creation or the latest call to setSocket().

Definition at line 113 of file LineIO.php.

Erebot\LineIO::inReadQueue ( )

Indicates whether there are lines in the input buffer waiting to be read.

Return values
boolWhether there are lines in the input buffer awaiting reading (true) or not (false).

Definition at line 344 of file LineIO.php.

Erebot\LineIO::inWriteQueue ( )

Indicates whether there are lines in the output buffer waiting to be written.

Return values
boolWhether there are lines in the output buffer awaiting writing (true) or not (false).

Definition at line 359 of file LineIO.php.

Erebot\LineIO::pop ( )

Returns a single line from the input buffer.

Return values
stringA single line from the input buffer.
nullThe input buffer did not contain any line.

Definition at line 262 of file LineIO.php.

Erebot\LineIO::push (   $line)

Adds a given line to the outgoing FIFO.

Parameters
string$lineThe line of text to send.
Exceptions
Erebot::InvalidValueExceptionThe $line contains invalid characters.

Definition at line 279 of file LineIO.php.

Erebot\LineIO::read ( )

Reads as many lines from the socket as possible.

Return values
booltrue if lines were successfully read, false is returned whenever EOF is reached or if this method has been called while the socket was still uninitialized..
Note
This method blocks until lines have been read of EOF is reached (whichever comes first).

Definition at line 216 of file LineIO.php.

Erebot\LineIO::setEOL (   $eol)

Sets the End-Of-Line (EOL) style used to process lines.

Parameters
opaque$eolThe type of line-endings to accept. This may be one of Erebot::LineIO::EOL_WIN, Erebot::LineIO::EOL_OLD_MAC, Erebot::LineIO::EOL_NEW_MAC, Erebot::LineIO::EOL_UNIX or Erebot::LineIO::EOL_ANY.

Definition at line 130 of file LineIO.php.

Erebot\LineIO::setSocket (   $socket)

Sets the socket this line reader operates on.

Parameters
resource$socketThe socket this reader will use from now on.

Definition at line 97 of file LineIO.php.

Erebot\LineIO::write ( )

Writes a single line from the output buffer to the socket.

Return values
intThe number of bytes successfully written on the socket.
falseThe connection was lost while trying to send the line or the output buffer was empty.

Definition at line 306 of file LineIO.php.


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