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

Provides core functionalities for Erebot. More...

+ Inheritance diagram for Erebot\Core:

Public Member Functions

 __clone ()
 
 __construct (\Erebot\Interfaces\Config\Main $config,\Erebot\IntlInterface $translator)
 
 __destruct ()
 
 addConnection (\Erebot\Interfaces\Connection $connection)
 
 addTimer (\Erebot\TimerInterface $timer)
 
 getConnections ()
 
 getRunningTime ()
 
 gettext ($message)
 
 getTimers ()
 
 handleSIGHUP ($signum)
 
 handleSignal ($signum)
 
 reload (\Erebot\Interfaces\Config\Main $config=null)
 
 removeConnection (\Erebot\Interfaces\Connection $connection)
 
 removeTimer (\Erebot\TimerInterface $timer)
 
 start (\Erebot\Interfaces\ConnectionFactory $factory)
 
 stop ()
 
- Public Member Functions inherited from Erebot\Interfaces\Core
 addConnection (\Erebot\Interfaces\Connection $connection)
 
 removeConnection (\Erebot\Interfaces\Connection $connection)
 
 start (\Erebot\Interfaces\ConnectionFactory $factory)
 

Protected Member Functions

 createConnections (\Erebot\Interfaces\ConnectionFactory $factory,\Erebot\Interfaces\Config\Main $config)
 
 realStart (\Erebot\Interfaces\ConnectionFactory $factory)
 

Protected Attributes

 $connections
 Connections to handle.
 
 $mainCfg
 Main configuration for the bot.
 
 $running
 Indicates whether the bot is currently running or not.
 
 $timers
 Timers to trigger.
 
 $translator
 Translator object for messages the bot may display.
 

Detailed Description

Provides core functionalities for Erebot.

This class is responsible for controlling the bot, from its start to its shutdown. This is the class that will create new connections, handle timers, apply multiplexing, etc.

The main method you will be interested in is Erebot::start() which starts the bot.

Definition at line 59 of file Core.php.

Constructor & Destructor Documentation

Erebot\Core::__construct ( \Erebot\Interfaces\Config\Main  $config,
\Erebot\IntlInterface  $translator 
)

Creates a new Erebot instance.

Parameters
Erebot::Interfaces::Config::MainInterface$configThe (main) configuration to use.
Erebot::IntlInterface$translatorA translator object that will provide translations for messages emitted by the core class.

Definition at line 86 of file Core.php.

Erebot\Core::__destruct ( )

Destruct an Erebot instance.

Definition at line 120 of file Core.php.

Member Function Documentation

Erebot\Core::__clone ( )

Copy-constructor.

Definition at line 128 of file Core.php.

Erebot\Core::addTimer ( \Erebot\TimerInterface  $timer)

Registers a timer for this instance.

Parameters
Erebot::TimerInterface$timerA timer to register.

Implements Erebot\Interfaces\Core.

Definition at line 419 of file Core.php.

Erebot\Core::createConnections ( \Erebot\Interfaces\ConnectionFactory  $factory,
\Erebot\Interfaces\Config\Main  $config 
)
protected

Creates the connections for this instance.

Parameters
Erebot::Interfaces::ConnectionFactory$factoryThe factory to use to create the connections.
Erebot::Interfaces::Config::Main$configThe main configuration for the bot.

Definition at line 547 of file Core.php.

Erebot\Core::getConnections ( )

Returns a list of all connections handled by the bot.

Return values
arrayA list of connections handled by this instance, as objects implementing Erebot::Interfaces::Connection.
Note
There is not much use for this method actually. The only case where you might need it is when you're willing to broadcast a message/command to all connections (such as to signal the bot shutting down).

Implements Erebot\Interfaces\Core.

Definition at line 134 of file Core.php.

Erebot\Core::getRunningTime ( )

Returns the number of seconds elapsed since the bot was last started.

Return values
falseThe bot is not running (Erebot::Interfaces::Core::start() has not been called yet).
integerThe number of seconds elapsed since the was last started.

Implements Erebot\Interfaces\Core.

Definition at line 474 of file Core.php.

Erebot\Core::gettext (   $message)

Returns the translation of a message in the primary language.

Use this method to get a translated message in the primary language. That is, using the language defined in the "language" attribute of the "configuration" tag in your XML configuration file.

Parameters
string$messageThe original message to translate, in english.
Return values
stringThe translation for this message or the original (english) message if no translation is available.

Implements Erebot\Interfaces\Core.

Definition at line 469 of file Core.php.

Erebot\Core::getTimers ( )

Returns a list of all timers currently registered.

Return values
arrayA list of timers registered for this instance, as objects implementing Erebot::TimerInterface.

Implements Erebot\Interfaces\Core.

Definition at line 414 of file Core.php.

Erebot\Core::handleSIGHUP (   $signum)

Handles requests to reload the configuration. Such requests are received as signals.

Parameters
int$signumThe number of the signal.

Definition at line 489 of file Core.php.

Erebot\Core::handleSignal (   $signum)

Handles request for a graceful shutdown of the bot. Such requests are received as signals.

Parameters
int$signumThe number of the signal.

Definition at line 361 of file Core.php.

References Erebot\Utils\parseHumanSize().

Erebot\Core::realStart ( \Erebot\Interfaces\ConnectionFactory  $factory)
protected

Really starts the bot.

Parameters
Erebot::Interfaces::ConnectionFactory$factoryFactory to use to create new connections.
Attention
This method does not return until the bot drops its connections. Therefore, this MUST be the last method you call in your script.
Note
This method is called by Erebot::start() and does the actual workload of running the bot.

Definition at line 153 of file Core.php.

Erebot\Core::reload ( \Erebot\Interfaces\Config\Main  $config = null)

Reload this instance of the bot.

This method makes the bot reload most of the data it currently relies on, such as configuration files.

Parameters
Erebot::Interfaces::Config::MainInterface$config(optional) The new configuration to use. If omitted, the configuration file currently in use is reloaded.

Definition at line 505 of file Core.php.

Erebot\Core::removeTimer ( \Erebot\TimerInterface  $timer)

Unregisters a timer.

Parameters
Erebot::TimerInterface$timerA timer to unregister.

Implements Erebot\Interfaces\Core.

Definition at line 430 of file Core.php.

Erebot\Core::stop ( )

Stops the bot.

Implements Erebot\Interfaces\Core.

Definition at line 325 of file Core.php.


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