Erebot  latest
A modular IRC bot for PHP 5.3+
Erebot\IrcConnection Class Reference

Handles a (possibly encrypted) connection to an IRC server. More...

+ Inheritance diagram for Erebot\IrcConnection:

Public Member Functions

 __construct (\Erebot\Interfaces\Core $bot,\Erebot\Interfaces\Config\Server $config=null, $events=array())
 
 __destruct ()
 
 addEventHandler (\Erebot\Interfaces\EventHandler $handler)
 
 addNumericHandler (\Erebot\Interfaces\NumericHandler $handler)
 
 connect ()
 
 disconnect ($quitMessage=null)
 
 dispatch (\Erebot\Interfaces\Event\Base\Generic $event)
 
 getBot ()
 
 getCollator ()
 
 getConfig ($chan)
 
 getEventsProducer ()
 
 getIO ()
 
 getModule ($name, $chan=null, $autoload=true)
 
 getModules ($chan=null)
 
 getNumericProfile ()
 
 getSocket ()
 
 getURIFactory ()
 
 handleCapabilities (\Erebot\Interfaces\EventHandler $handler,\Erebot\Event\ServerCapabilities $event)
 
 handleConnect (\Erebot\Interfaces\EventHandler $handler,\Erebot\Interfaces\Event\Connect $event)
 
 isChannel ($chan)
 
 isConnected ()
 
 loadModule ($module, $chan=null)
 
 process ()
 Processes commands queued in the input buffer.
 
 read ()
 
 reload (\Erebot\Interfaces\Config\Server $config)
 
 removeEventHandler (\Erebot\Interfaces\EventHandler $handler)
 
 removeNumericHandler (\Erebot\Interfaces\NumericHandler $handler)
 
 setCollator (\Erebot\Interfaces\IrcCollator $collator)
 
 setNumericProfile (\Erebot\NumericProfile\Base $profile)
 
 setURIFactory ($factory)
 
 write ()
 
- Public Member Functions inherited from Erebot\Interfaces\EventDispatcher
 addEventHandler (\Erebot\Interfaces\EventHandler $handler)
 
 addNumericHandler (\Erebot\Interfaces\NumericHandler $handler)
 
 removeEventHandler (\Erebot\Interfaces\EventHandler $handler)
 
 removeNumericHandler (\Erebot\Interfaces\NumericHandler $handler)
 
- Public Member Functions inherited from Erebot\Interfaces\Collated
 setCollator (\Erebot\Interfaces\IrcCollator $collator)
 

Protected Member Functions

 dispatchEvent (\Erebot\Interfaces\Event\Base\Generic $event)
 
 dispatchNumeric (\Erebot\Interfaces\Event\Numeric $numeric)
 
 loadModules (\Erebot\Interfaces\Config\Server $config, $flags)
 
 realLoadModule ($module, $chan, $flags, &$plainModules, &$channelModules)
 

Protected Attributes

 $bot
 A bot object implementing the Erebot::Interfaces::Core interface.
 
 $channelModules
 Maps channels to their loaded modules.
 
 $collator
 Collator for IRC nicknames.
 
 $config
 
 $connected
 Whether this connection is actually... well, connected.
 
 $events
 A list of event handlers.
 
 $eventsProducer
 Class to use to parse IRC messages and produce events from them.
 
 $io
 I/O manager for the socket.
 
 $numericProfile
 Numeric profile.
 
 $numerics
 A list of numeric handlers.
 
 $plainModules
 Maps modules names to modules instances.
 
 $socket
 The underlying socket, represented as a stream.
 
 $uriFactory
 Factory to use to parse URI.
 

Detailed Description

Handles a (possibly encrypted) connection to an IRC server.

Definition at line 27 of file IrcConnection.php.

Constructor & Destructor Documentation

Erebot\IrcConnection::__construct ( \Erebot\Interfaces\Core  $bot,
\Erebot\Interfaces\Config\Server  $config = null,
  $events = array() 
)

Constructs the object which will hold a connection.

Parameters
Erebot::Interfaces::Core$botA bot instance.
Erebot::Interfaces::Config::Server$configThe connfiguration for this connection.
array$events(optional) A mapping of event interface names to the class that must be used to produce such events (factory).
Note
No connection (in the socket sense) is actually created until Erebot::Interfaces::Connection::connect() is called.

Definition at line 90 of file IrcConnection.php.

Erebot\IrcConnection::__destruct ( )

Destructor.

Definition at line 132 of file IrcConnection.php.

Member Function Documentation

Erebot\IrcConnection::connect ( )

Makes the actual connection to an IRC server, using the configuration data passed to the constructor.

Exceptions
Erebot::ConnectionFailureExceptionThrown whenever the bot fails to establish a connection to the given server.

Implements Erebot\Interfaces\Connection.

Definition at line 314 of file IrcConnection.php.

Erebot\IrcConnection::disconnect (   $quitMessage = null)

Disconnects the bot from that particular IRC server.

Parameters
string$quitMessage(optional) A message which will be visible by other users when the bot gets disconnected. If no message is given, the IrcConnector module is probed for its "quit_message" parameter. If no message is available, the bot quits with an empty string as its quit message.

Implements Erebot\Interfaces\Connection.

Definition at line 464 of file IrcConnection.php.

References Erebot\Utils\stringifiable().

Erebot\IrcConnection::dispatch ( \Erebot\Interfaces\Event\Base\Generic  $event)

Dispatches the given event to handlers which have been registered for this type of event.

Parameters
Erebot::Interfaces::Event::Base::Generic$eventAn event to dispatch.
Note
For the purposes of this method, numeric messages (objects implementing the Erebot::Interfaces::Event::Numeric interface) are considered "events" too.

Implements Erebot\Interfaces\EventDispatcher.

Definition at line 802 of file IrcConnection.php.

Erebot\IrcConnection::dispatchEvent ( \Erebot\Interfaces\Event\Base\Generic  $event)
protected

Dispatches the given event to handlers which have been registered for this type of event.

Parameters
Erebot::Interfaces::Event::Base::Generic$eventAn event to dispatch.

Definition at line 755 of file IrcConnection.php.

Erebot\IrcConnection::dispatchNumeric ( \Erebot\Interfaces\Event\Numeric  $numeric)
protected

Dispatches the given numeric event to handlers which have been registered for this type of numeric.

Parameters
Erebot::Interfaces::Event::Numeric$numericA numeric message to dispatch.

Definition at line 782 of file IrcConnection.php.

Erebot\IrcConnection::getBot ( )

Returns the bot instance this connection is associated with.

Return values
Erebot::Interfaces::CoreAn instance of the core class (Erebot).

Implements Erebot\Interfaces\Connection.

Definition at line 519 of file IrcConnection.php.

Erebot\IrcConnection::getCollator ( )

Returns the collator associated with this connection.

Return values
Erebot::Interfaces::IrcCollatorThe collator for this connection.

Implements Erebot\Interfaces\Collated.

Definition at line 910 of file IrcConnection.php.

Erebot\IrcConnection::getConfig (   $chan)

Retrieves the configuration for a given channel.

Parameters
null | string$chanThe name of the IRC channel for which a configuration must be retrieved. If $chan is null, the configuration associated with this object is returned instead (an instance of the Erebot::Interfaces::Config::Server).
Return values
Erebot::Interfaces::Config::ChannelThe configuration for the given channel, if there is one.
Erebot::Interfaces::Config::ServerOtherwise, the configuration for the associated IRC server.
Exceptions
Erebot::NotFoundExceptionNo Erebot::Interfaces::Config::Channel object exists for the given channel.

Implements Erebot\Interfaces\Connection.

Definition at line 498 of file IrcConnection.php.

Erebot\IrcConnection::getEventsProducer ( )

Returns the object used to produce events.

Return values
Erebot::Interfaces::IrcParserObject used to produce events.
Note
This method is somewhat misnamed, since in reality the object it returns does more than merely producing events—it is a full-blown IRC parser.

Implements Erebot\Interfaces\IrcConnection.

Definition at line 915 of file IrcConnection.php.

Erebot\IrcConnection::getIO ( )

Returns the object used to handle I/O (input/output) with this connection.

Note
Do not use this object directly unless you know what you're doing. Instead, use the methods from the appropriate interfaces: Erebot::Interfaces::SendingConnection for writing and Erebot::Interfaces::ReceivingConnection for reading.

Implements Erebot\Interfaces\Connection.

Definition at line 524 of file IrcConnection.php.

Erebot\IrcConnection::getModule (   $name,
  $chan = null,
  $autoload = true 
)

Returns an instance of a given module on a given channel.

Parameters
string$nameThe name of the module (ie. the name of the class implementing the feature we're interested in).
string$chan(optional) An IRC channel name. If given, the bot will try to return an instance which is specific to that particular channel, before falling back to a shared instance. Otherwise, this method only looks for a shared instance.
bool$autoload(optional) Whether the module should be autoloaded if it could not be found first time around (true) or not (false). The default is to autoload missing modules.
Return values
Erebot::Module::BaseAn instance of the given module.
Exceptions
Erebot::InvalidValueExceptionThrown when an invalid $type is passed.
Erebot::NotFoundExceptionThrown if no instance of the given module could be found.

Implements Erebot\Interfaces\ModuleContainer.

Definition at line 690 of file IrcConnection.php.

Erebot\IrcConnection::getModules (   $chan = null)

Returns the modules loaded for a given channel or for the whole connection.

Parameters
string$chan(optional) An IRC channel name. If given, both the modules which were specifically loaded for that channel and the shared modules are returned. Otherwise, only the shared modules are returned.
Return values
arrayA list of module instances implementing Erebot::Module::Base.

Implements Erebot\Interfaces\ModuleContainer.

Definition at line 679 of file IrcConnection.php.

Erebot\IrcConnection::getNumericProfile ( )

Returns the numeric profile associated with this connection.

Return values
Erebot::NumericProfile::BaseThe numeric profile associated with this connection.

Implements Erebot\Interfaces\IrcConnection.

Definition at line 176 of file IrcConnection.php.

Erebot\IrcConnection::getSocket ( )

Returns the underlying transport implementation for this connection.

Return values
streamReturns this connection's socket, as a PHP stream.
Note
You generally don't need any sort of access to this stream, but it may be useful in cases where you need to do a select() on the connection.

Implements Erebot\Interfaces\Connection.

Definition at line 514 of file IrcConnection.php.

Erebot\IrcConnection::getURIFactory ( )

Returns the name of the class used to parse Uniform Resource Identifiers.

Return values
stringName of the class used to parse an URI.

Definition at line 153 of file IrcConnection.php.

Erebot\IrcConnection::handleCapabilities ( \Erebot\Interfaces\EventHandler  $handler,
\Erebot\Event\ServerCapabilities  $event 
)

Handles the "ServerCapabilities" event.

Parameters
Erebot::Interfaces::EventHandler$handlerThe event handler responsible for calling this method.
Erebot::Event::ServerCapabilities$eventThe "ServerCapabilities" event to process.

Definition at line 856 of file IrcConnection.php.

Erebot\IrcConnection::handleConnect ( \Erebot\Interfaces\EventHandler  $handler,
\Erebot\Interfaces\Event\Connect  $event 
)

Handles the "Connect" event.

Parameters
Erebot::Interfaces::EventHandler$handlerThe event handler responsible for calling this method.
Erebot::Interfaces::Event::Connect$eventThe "Connect" event to process.

Definition at line 885 of file IrcConnection.php.

Erebot\IrcConnection::isChannel (   $chan)

Determines if the given string is a valid channel name or not. A channel name usually starts with the hash symbol (#). Valid characters for the rest of the name vary between IRC networks.

Parameters
$chanTentative channel name.
Return values
booltrue if $chan is a valid channel name, false otherwise.
Exceptions
Erebot::InvalidValueException::$chanis not a string or is empty.

Implements Erebot\Interfaces\IrcConnection.

Definition at line 810 of file IrcConnection.php.

Erebot\IrcConnection::isConnected ( )

Returns whether this connection object is currently connected to a server.

Return values
booltrue if the connection is really connected, false otherwise.

Implements Erebot\Interfaces\Connection.

Definition at line 309 of file IrcConnection.php.

Erebot\IrcConnection::loadModule (   $module,
  $chan = null 
)

Loads a module for a specific channel or for the whole connection.

Parameters
string$moduleThe name of the module to load.
NULL | string$chan(optional) An IRC channel name. If given, the module will be loaded and a specific instance will be created for that $chan. Otherwise, an instance will be created that will be shared across channels on the same connection.
Return values
Erebot::Module::BaseAn instance of the module.
Note
Only one instance of a module is ever created for a channel or the pool of shared modules. Therefore, it is safe to call this method multiple times with the same parameters.
Exceptions
Erebot::InvalidValueExceptionThrown when invalid values are found in the (meta)data of the module.
Erebot::NotFoundExceptionThrown when a required dependency could not be loaded. You may want to load the required dependency and then try to load the module again.

Implements Erebot\Interfaces\ModuleContainer.

Definition at line 668 of file IrcConnection.php.

Erebot\IrcConnection::loadModules ( \Erebot\Interfaces\Config\Server  $config,
  $flags 
)
protected

(Re)Load the modules for this connection.

Parameters
Erebot::Interfaces::Config::Server$configA server configuration that describes the modules to load.
int$flagsFlags that will be passed to the reload() method of every module that needs reloading. This is a bitwise-OR of the RELOAD_* constants defined in Erebot::Module::Base.

Definition at line 214 of file IrcConnection.php.

Erebot\IrcConnection::read ( )

Processes data from the incoming buffer.

Once this method has been called, all lines awaiting processing in the incoming buffer have been transferred to the incoming FIFO. You must call Erebot::Connection::processQueuedData() after that in order to process the lines in the FIFO. This is done so that a throttling policy may be put in place if needed (eg. for an anti-flood system).

Implements Erebot\Interfaces\ReceivingConnection.

Definition at line 529 of file IrcConnection.php.

Erebot\IrcConnection::realLoadModule (   $module,
  $chan,
  $flags,
$plainModules,
$channelModules 
)
protected

Load a single module for this connection.

Parameters
string$moduleName of the module to load. If the module is already loaded, nothing will happen.
string | null$chanName of the IRC channel for which this module is being loaded. Pass null to load a module globally (for the whole connection) rather than for a specific IRC channel.
opaque$flagsBitwise-OR combination of flags to pass to the module's initialization method.
array$plainModulesAn associative array containing the global modules currently loaded. This array will be updated if it needs to be once the module has been successfully loaded.
array$channelModulesAn associative array containing the modules currently loaded for the given IRC channel. This array will be updated if it needs to be once the module has been successfully loaded.
Return values
Erebot::Module::BaseAn instance of the module with the given name.

Definition at line 621 of file IrcConnection.php.

Erebot\IrcConnection::reload ( \Erebot\Interfaces\Config\Server  $config)

Reloads/sets the configuration for this connection.

Parameters
Erebot::Interfaces::Config::Server$configThe new configuration for this connection.

Definition at line 192 of file IrcConnection.php.

Erebot\IrcConnection::setCollator ( \Erebot\Interfaces\IrcCollator  $collator)

Sets the collector to use for this connection.

Parameters
Erebot::Interfaces::Collator$collatorThe new collator to use for this connection.

Definition at line 898 of file IrcConnection.php.

Erebot\IrcConnection::setNumericProfile ( \Erebot\NumericProfile\Base  $profile)

Sets the new numeric profile for this connection.

Parameters
Erebot::NumericProfile::Base$profileThe new numeric profile to use for this connection.

Implements Erebot\Interfaces\IrcConnection.

Definition at line 181 of file IrcConnection.php.

Erebot\IrcConnection::setURIFactory (   $factory)

Sets the class to use as a factory to parse Uniform Resource Identifiers.

Parameters
string$factoryName of the class to use to parse an URI.

Definition at line 165 of file IrcConnection.php.

Erebot\IrcConnection::write ( )

Sends a single line of data from the outgoing FIFO to the underlying socket.

This method is misnamed, because it acts on a FIFO rather than on raw data. This method can be called multiple times (such as in a loop) to send all lines in the outgoing FIFO. This is done so that a throttling policy may be put in place if needed (eg. for an anti-flood system).

Implements Erebot\Interfaces\SendingConnection.

Definition at line 553 of file IrcConnection.php.

Member Data Documentation

Erebot\IrcConnection::$config
protected

A configuration object implementing the Erebot::Interfaces::Config::Server interface.

Definition at line 33 of file IrcConnection.php.


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