PHP Class Phergie\Irc\Client\React\Client

Inheritance: extends Evenement\EventEmitter, implements Phergie\Irc\Client\React\ClientInterface, implements Phergie\Irc\Client\React\LoopAwareInterface, implements Phergie\Irc\Client\React\LoopAccessorInterface
Exibir arquivo Open project: phergie/phergie-irc-client-react Class Usage Examples

Protected Properties

Property Type Description
$activeConnections SplObjectStorage Contains all connection instances associated with an active socket stream
$dnsServer string
$logger Psr\Log\LoggerInterface Logging stream
$loop React\EventLoop\LoopInterface Event loop
$resolver React\Dns\Resolver\Resolver
$secureConnector React\SocketClient\SecureConnector Connector used to establish SSL connections
$tickInterval float Interval in seconds between irc.tick events

Public Methods

Method Description
addConnection ( Phergie\Irc\ConnectionInterface $connection ) Initializes an IRC connection.
addPeriodicTimer ( numeric $interval, callable $callback ) : React\Event\Timer\TimerInterface Adds a recurring callback to execute on a specified interval. Proxies to addPeriodTimer() implementation of the event loop implementation returned by getLoop().
addTimer ( numeric $interval, callable $callback ) : React\Event\Timer\TimerInterface Adds a one-time callback to execute after a specified amount of time has passed. Proxies to addTimer() implementation of the event loop implementation returned by getLoop().
cancelTimer ( React\EventLoop\Timer\TimerInterface $timer ) Cancels a specified timer created using addTimer() or addPeriodicTimer(). Proxies to the cancelTimer() implementation of the event loop implementation returned by getLoop().
getActiveConnections ( ) : Phergie\Irc\ConnectionInterface[] Gets an array of all connections associated with an active socket stream.
getDnsServer ( ) : string Returns the configured DNS server
getLogger ( ) : Psr\Log\LoggerInterface Returns a stream instance for logging data on the socket connection.
getLoop ( ) : React\EventLoop\LoopInterface Returns the event loop dependency, initializing it if needed.
getResolver ( ) : React\Dns\Resolver\Resolver Get the DNS Resolver, if one isn't set in instance will be created.
getTickInterval ( ) : float Returns the interval in seconds between irc.tick events.
isTimerActive ( React\EventLoop\Timer\TimerInterface $timer ) : boolean Checks if a timer created using addTimer() or addPeriodicTimer() is active. Proxies to the isTimerActive() implementation of the event loop implementation returned by getLoop().
run ( Phergie\Irc\ConnectionInterface | Phergie\Irc\ConnectionInterface[] $connections, boolean $autorun = true ) Executes the event loop, which continues running until no active connections remain.
setDnsServer ( string $dnsServer = '8.8.8.8' ) Set the DNS server to use when looking up IP's
setLogger ( Psr\Log\LoggerInterface $logger ) Sets a logger for logging data on the socket connection.
setLoop ( React\EventLoop\LoopInterface $loop ) Sets the event loop dependency.
setResolver ( React\Dns\Resolver\Resolver $resolver = null ) Sets the DNS Resolver.
setTickInterval ( float $tickInterval ) Sets the interval in seconds between irc.tick events.

Protected Methods

Method Description
addActiveConnection ( Phergie\Irc\ConnectionInterface $connection ) Add a connection instance to the active connection store
addLogging ( Evenement\EventEmitter $emitter, Phergie\Irc\ConnectionInterface $connection ) Adds an event listener to log data emitted by a stream.
addSecureConnection ( Phergie\Irc\ConnectionInterface $connection ) Initializes a secured connection.
addUnsecuredConnection ( Phergie\Irc\ConnectionInterface $connection ) Initializes an unsecured connection.
configureStreams ( Phergie\Irc\ConnectionInterface $connection, React\Stream\DuplexStreamInterface $stream, Phergie\Irc\Client\React\WriteStream $write ) Configure streams to handle messages received from and sent to the server.
emitConnectionError ( Phergie\Irc\Client\React\Exception $exception, Phergie\Irc\ConnectionInterface $connection ) Emits a connection error event.
getContext ( Phergie\Irc\ConnectionInterface $connection ) : array Derives a set of socket context options for a given connection.
getEndCallback ( Phergie\Irc\Client\React\ReadStream $read, Phergie\Irc\Client\React\WriteStream $write, Phergie\Irc\ConnectionInterface $connection, React\EventLoop\Timer\TimerInterface $timer ) : callable Returns a callback for when a connection is terminated, whether explicitly by the bot or server or as a result of loss of connectivity.
getErrorCallback ( Phergie\Irc\ConnectionInterface $connection ) : callable Returns a callback for proxying connection error events to listeners of the client.
getForceIpv4Flag ( Phergie\Irc\ConnectionInterface $connection ) : boolean Extracts the value of the force-ipv4 option from a given connection.
getOutputLogCallback ( Phergie\Irc\ConnectionInterface $connection, string $level, string $prefix = null ) : callable Generates a closure for stream output logging.
getReadCallback ( Phergie\Irc\Client\React\WriteStream $write, Phergie\Irc\ConnectionInterface $connection ) : callable Returns a callback for proxying IRC events from the read stream to IRC listeners of the client.
getReadStream ( Phergie\Irc\ConnectionInterface $connection ) : Phergie\Irc\Client\React\ReadStream Returns a stream instance for parsing messages from the server and emitting them as events.
getRemote ( Phergie\Irc\ConnectionInterface $connection ) : string Derives a remote for a given connection.
getSecureConnector ( ) : React\SocketClient\SecureConnector Returns a connector for establishing SSL connections.
getSocket ( string $remote, array $context ) : resource Returns a socket configured for a specified remote.
getStream ( resource $socket ) : React\Stream\DuplexStreamInterface Returns a stream for a socket connection.
getTickCallback ( Phergie\Irc\Client\React\WriteStream $write, Phergie\Irc\ConnectionInterface $connection ) Returns a callback executed periodically to allow events to be sent asynchronously versus in response to received or sent events.
getTransport ( Phergie\Irc\ConnectionInterface $connection ) : string Derives the transport for a given connection.
getWriteCallback ( Phergie\Irc\Client\React\WriteStream $write, Phergie\Irc\ConnectionInterface $connection ) : callable Returns a callback for proxying events from the write stream to IRC listeners of the client.
getWriteStream ( Phergie\Irc\ConnectionInterface $connection ) : Phergie\Irc\Client\React\WriteStream Returns a stream instance for sending events to the server.
identifyUser ( Phergie\Irc\ConnectionInterface $connection, Phergie\Irc\Client\React\WriteStream $writeStream ) Identifies the user to a server.
initializeConnection ( string $remote, Phergie\Irc\ConnectionInterface $connection ) Initializes an added connection.
initializeStream ( React\Stream\DuplexStreamInterface $stream, Phergie\Irc\ConnectionInterface $connection ) Configures an established stream for a given connection.
processInput ( array $message, Phergie\Irc\Client\React\WriteStream $write, Phergie\Irc\ConnectionInterface $connection ) There are certain incoming events that the client processes internally.
removeActiveConnection ( Phergie\Irc\ConnectionInterface $connection ) Remove a connection instance from the active connections store

Method Details

addActiveConnection() protected method

Add a connection instance to the active connection store
protected addActiveConnection ( Phergie\Irc\ConnectionInterface $connection )
$connection Phergie\Irc\ConnectionInterface

addConnection() public method

Emits connect.before.each and connect.after.each events before and after connection attempts are established, respectively. Emits a connect.error event if a connection attempt fails.
public addConnection ( Phergie\Irc\ConnectionInterface $connection )
$connection Phergie\Irc\ConnectionInterface Metadata for connection to establish

addLogging() protected method

Adds an event listener to log data emitted by a stream.
protected addLogging ( Evenement\EventEmitter $emitter, Phergie\Irc\ConnectionInterface $connection )
$emitter Evenement\EventEmitter
$connection Phergie\Irc\ConnectionInterface Connection corresponding to the stream

addPeriodicTimer() public method

Adds a recurring callback to execute on a specified interval. Proxies to addPeriodTimer() implementation of the event loop implementation returned by getLoop().
public addPeriodicTimer ( numeric $interval, callable $callback ) : React\Event\Timer\TimerInterface
$interval numeric Number of seconds to wait between executions of callback
$callback callable Callback to execute
return React\Event\Timer\TimerInterface Added timer

addSecureConnection() protected method

Initializes a secured connection.
protected addSecureConnection ( Phergie\Irc\ConnectionInterface $connection )
$connection Phergie\Irc\ConnectionInterface

addTimer() public method

Adds a one-time callback to execute after a specified amount of time has passed. Proxies to addTimer() implementation of the event loop implementation returned by getLoop().
public addTimer ( numeric $interval, callable $callback ) : React\Event\Timer\TimerInterface
$interval numeric Number of seconds to wait before executing callback
$callback callable Callback to execute
return React\Event\Timer\TimerInterface Added timer

addUnsecuredConnection() protected method

Initializes an unsecured connection.
protected addUnsecuredConnection ( Phergie\Irc\ConnectionInterface $connection )
$connection Phergie\Irc\ConnectionInterface

cancelTimer() public method

Cancels a specified timer created using addTimer() or addPeriodicTimer(). Proxies to the cancelTimer() implementation of the event loop implementation returned by getLoop().
public cancelTimer ( React\EventLoop\Timer\TimerInterface $timer )
$timer React\EventLoop\Timer\TimerInterface Timer returned by addTimer() or addPeriodicTimer()

configureStreams() protected method

Configure streams to handle messages received from and sent to the server.
protected configureStreams ( Phergie\Irc\ConnectionInterface $connection, React\Stream\DuplexStreamInterface $stream, Phergie\Irc\Client\React\WriteStream $write )
$connection Phergie\Irc\ConnectionInterface Metadata for the connection over which messages are being exchanged
$stream React\Stream\DuplexStreamInterface Stream representing the connection to the server
$write Phergie\Irc\Client\React\WriteStream Stream used to send events to the server

emitConnectionError() protected method

Emits a connection error event.
protected emitConnectionError ( Phergie\Irc\Client\React\Exception $exception, Phergie\Irc\ConnectionInterface $connection )
$exception Phergie\Irc\Client\React\Exception
$connection Phergie\Irc\ConnectionInterface

getActiveConnections() public method

Gets an array of all connections associated with an active socket stream.
public getActiveConnections ( ) : Phergie\Irc\ConnectionInterface[]
return Phergie\Irc\ConnectionInterface[]

getContext() protected method

Derives a set of socket context options for a given connection.
protected getContext ( Phergie\Irc\ConnectionInterface $connection ) : array
$connection Phergie\Irc\ConnectionInterface
return array Associative array of context option key-value pairs

getDnsServer() public method

Returns the configured DNS server
public getDnsServer ( ) : string
return string

getEndCallback() protected method

Returns a callback for when a connection is terminated, whether explicitly by the bot or server or as a result of loss of connectivity.
protected getEndCallback ( Phergie\Irc\Client\React\ReadStream $read, Phergie\Irc\Client\React\WriteStream $write, Phergie\Irc\ConnectionInterface $connection, React\EventLoop\Timer\TimerInterface $timer ) : callable
$read Phergie\Irc\Client\React\ReadStream Read stream for this connection
$write Phergie\Irc\Client\React\WriteStream Write stream for this connection
$connection Phergie\Irc\ConnectionInterface Terminated connection
$timer React\EventLoop\Timer\TimerInterface Timer used to handle asynchronously queued events on the connection, which must be cancelled
return callable

getErrorCallback() protected method

Returns a callback for proxying connection error events to listeners of the client.
protected getErrorCallback ( Phergie\Irc\ConnectionInterface $connection ) : callable
$connection Phergie\Irc\ConnectionInterface Connection on which the error occurred
return callable

getForceIpv4Flag() protected method

Extracts the value of the force-ipv4 option from a given connection.
protected getForceIpv4Flag ( Phergie\Irc\ConnectionInterface $connection ) : boolean
$connection Phergie\Irc\ConnectionInterface
return boolean TRUE to force use of IPv4, FALSE otherwise

getLogger() public method

Returns a stream instance for logging data on the socket connection.
public getLogger ( ) : Psr\Log\LoggerInterface
return Psr\Log\LoggerInterface

getLoop() public method

Returns the event loop dependency, initializing it if needed.
public getLoop ( ) : React\EventLoop\LoopInterface
return React\EventLoop\LoopInterface

getOutputLogCallback() protected method

Generates a closure for stream output logging.
protected getOutputLogCallback ( Phergie\Irc\ConnectionInterface $connection, string $level, string $prefix = null ) : callable
$connection Phergie\Irc\ConnectionInterface
$level string Evenement logging level to use
$prefix string Prefix string for log lines (optional)
return callable

getReadCallback() protected method

Returns a callback for proxying IRC events from the read stream to IRC listeners of the client.
protected getReadCallback ( Phergie\Irc\Client\React\WriteStream $write, Phergie\Irc\ConnectionInterface $connection ) : callable
$write Phergie\Irc\Client\React\WriteStream Write stream corresponding to the read stream on which the event occurred
$connection Phergie\Irc\ConnectionInterface Connection on which the event occurred
return callable

getReadStream() protected method

Returns a stream instance for parsing messages from the server and emitting them as events.
protected getReadStream ( Phergie\Irc\ConnectionInterface $connection ) : Phergie\Irc\Client\React\ReadStream
$connection Phergie\Irc\ConnectionInterface Connection corresponding to the read stream
return Phergie\Irc\Client\React\ReadStream

getRemote() protected method

Derives a remote for a given connection.
protected getRemote ( Phergie\Irc\ConnectionInterface $connection ) : string
$connection Phergie\Irc\ConnectionInterface
return string Remote usable to establish a socket connection

getResolver() public method

Get the DNS Resolver, if one isn't set in instance will be created.
public getResolver ( ) : React\Dns\Resolver\Resolver
return React\Dns\Resolver\Resolver

getSecureConnector() protected method

Returns a connector for establishing SSL connections.
protected getSecureConnector ( ) : React\SocketClient\SecureConnector
return React\SocketClient\SecureConnector

getSocket() protected method

Returns a socket configured for a specified remote.
protected getSocket ( string $remote, array $context ) : resource
$remote string Address to connect the socket to (e.g. tcp://irc.freenode.net:6667)
$context array Context options for the socket
return resource

getStream() protected method

Returns a stream for a socket connection.
protected getStream ( resource $socket ) : React\Stream\DuplexStreamInterface
$socket resource Socket for the connection to the server
return React\Stream\DuplexStreamInterface

getTickCallback() protected method

Returns a callback executed periodically to allow events to be sent asynchronously versus in response to received or sent events.
protected getTickCallback ( Phergie\Irc\Client\React\WriteStream $write, Phergie\Irc\ConnectionInterface $connection )
$write Phergie\Irc\Client\React\WriteStream Stream used to send events to the server
$connection Phergie\Irc\ConnectionInterface Connection to receive the event

getTickInterval() public method

Returns the interval in seconds between irc.tick events.
public getTickInterval ( ) : float
return float

getTransport() protected method

Derives the transport for a given connection.
protected getTransport ( Phergie\Irc\ConnectionInterface $connection ) : string
$connection Phergie\Irc\ConnectionInterface
return string Transport usable in the URI for a stream

getWriteCallback() protected method

Returns a callback for proxying events from the write stream to IRC listeners of the client.
protected getWriteCallback ( Phergie\Irc\Client\React\WriteStream $write, Phergie\Irc\ConnectionInterface $connection ) : callable
$write Phergie\Irc\Client\React\WriteStream Write stream corresponding to the read stream on which the event occurred
$connection Phergie\Irc\ConnectionInterface Connection on which the event occurred
return callable

getWriteStream() protected method

Returns a stream instance for sending events to the server.
protected getWriteStream ( Phergie\Irc\ConnectionInterface $connection ) : Phergie\Irc\Client\React\WriteStream
$connection Phergie\Irc\ConnectionInterface Connection corresponding to the read stream
return Phergie\Irc\Client\React\WriteStream

identifyUser() protected method

Identifies the user to a server.
protected identifyUser ( Phergie\Irc\ConnectionInterface $connection, Phergie\Irc\Client\React\WriteStream $writeStream )
$connection Phergie\Irc\ConnectionInterface Connection on which to identify the user
$writeStream Phergie\Irc\Client\React\WriteStream Stream to receive commands identifying the user

initializeConnection() protected method

Initializes an added connection.
protected initializeConnection ( string $remote, Phergie\Irc\ConnectionInterface $connection )
$remote string
$connection Phergie\Irc\ConnectionInterface

initializeStream() protected method

Configures an established stream for a given connection.
protected initializeStream ( React\Stream\DuplexStreamInterface $stream, Phergie\Irc\ConnectionInterface $connection )
$stream React\Stream\DuplexStreamInterface
$connection Phergie\Irc\ConnectionInterface

isTimerActive() public method

Checks if a timer created using addTimer() or addPeriodicTimer() is active. Proxies to the isTimerActive() implementation of the event loop implementation returned by getLoop().
public isTimerActive ( React\EventLoop\Timer\TimerInterface $timer ) : boolean
$timer React\EventLoop\Timer\TimerInterface Timer returned by addTimer() or addPeriodicTimer()
return boolean TRUE if the specified timer is active, FALSE otherwise

processInput() protected method

These functions are essential to the client-server relationship: for example, updating the connection's stored nickname, responding to PING events, etc. Any user-level IRC functionality handled internally by the client should be implemented here.
protected processInput ( array $message, Phergie\Irc\Client\React\WriteStream $write, Phergie\Irc\ConnectionInterface $connection )
$message array Parser output
$write Phergie\Irc\Client\React\WriteStream Write stream corresponding to the read stream on which the event occurred
$connection Phergie\Irc\ConnectionInterface Connection on which the event occurred

removeActiveConnection() protected method

Remove a connection instance from the active connections store
protected removeActiveConnection ( Phergie\Irc\ConnectionInterface $connection )
$connection Phergie\Irc\ConnectionInterface

run() public method

Executes the event loop, which continues running until no active connections remain.
public run ( Phergie\Irc\ConnectionInterface | Phergie\Irc\ConnectionInterface[] $connections, boolean $autorun = true )
$connections Phergie\Irc\ConnectionInterface | Phergie\Irc\ConnectionInterface[]
$autorun boolean

setDnsServer() public method

Set the DNS server to use when looking up IP's
public setDnsServer ( string $dnsServer = '8.8.8.8' )
$dnsServer string

setLogger() public method

Sets a logger for logging data on the socket connection.
public setLogger ( Psr\Log\LoggerInterface $logger )
$logger Psr\Log\LoggerInterface

setLoop() public method

Sets the event loop dependency.
public setLoop ( React\EventLoop\LoopInterface $loop )
$loop React\EventLoop\LoopInterface

setResolver() public method

Sets the DNS Resolver.
public setResolver ( React\Dns\Resolver\Resolver $resolver = null )
$resolver React\Dns\Resolver\Resolver

setTickInterval() public method

Sets the interval in seconds between irc.tick events.
public setTickInterval ( float $tickInterval )
$tickInterval float

Property Details

$activeConnections protected_oe property

Contains all connection instances associated with an active socket stream
protected SplObjectStorage $activeConnections
return SplObjectStorage

$dnsServer protected_oe property

protected string $dnsServer
return string

$logger protected_oe property

Logging stream
protected LoggerInterface,Psr\Log $logger
return Psr\Log\LoggerInterface

$loop protected_oe property

Event loop
protected LoopInterface,React\EventLoop $loop
return React\EventLoop\LoopInterface

$resolver protected_oe property

protected Resolver,React\Dns\Resolver $resolver
return React\Dns\Resolver\Resolver

$secureConnector protected_oe property

Connector used to establish SSL connections
protected SecureConnector,React\SocketClient $secureConnector
return React\SocketClient\SecureConnector

$tickInterval protected_oe property

Interval in seconds between irc.tick events
protected float $tickInterval
return float