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

An event handler which will call a callback function/method whenever a set of conditions are met. More...

+ Inheritance diagram for Erebot\EventHandler:

Public Member Functions

 __construct (\Erebot\CallableInterface $callback,\Erebot\Interfaces\Event\Match $filter=null)
 
 __destruct ()
 Destructor.
 
 getCallback ()
 
 getFilter ()
 
 handleEvent (\Erebot\Interfaces\Event\Base\Generic $event)
 
 setCallback (\Erebot\CallableInterface $callback)
 
 setFilter (\Erebot\Interfaces\Event\Match $filter=null)
 

Protected Attributes

 $callback
 Callable object to use when this handler is triggered.
 
 $filter
 Filtering object to decide whether the callback must be called or not.
 

Detailed Description

An event handler which will call a callback function/method whenever a set of conditions are met.

Such conditions may be related to the event being of a certain type, being addressed to a certain target and/or having a certain content.

Definition at line 31 of file EventHandler.php.

Constructor & Destructor Documentation

Erebot\EventHandler::__construct ( \Erebot\CallableInterface  $callback,
\Erebot\Interfaces\Event\Match  $filter = null 
)

Constructs an event handler.

Parameters
callback$callbackThe callback function/method which will be called when an event is received which meets the $constraints, is part of valid $targets and passed the $filters successfully.
null | Erebot::Interfaces::Event::Match$filter(optional) A filter which must be matched for the callback associated with this handler to be called.

Definition at line 52 of file EventHandler.php.

Member Function Documentation

Erebot\EventHandler::getCallback ( )

Returns a reference to the callback which was associated with this handler during construction.

Return values
callbackThe callback associated with this handler.

Implements Erebot\Interfaces\EventHandler.

Definition at line 71 of file EventHandler.php.

Erebot\EventHandler::getFilter ( )

Returns the filter currently associated with this event handler.

Return values
Erebot::Interfaces::Event::MatchThe current filter associated with this event handler, or NULL if no filter has been set yet.

Implements Erebot\Interfaces\EventHandler.

Definition at line 82 of file EventHandler.php.

Erebot\EventHandler::handleEvent ( \Erebot\Interfaces\Event\Base\Generic  $event)

Given an event, this method does its best to handler it.

Parameters
Erebot::Interfaces::Event::Base::Generic$eventAn event to try to handle.
Note
It is this method's responsability to make appropriate checks and act upon the result of those checks. It may for example check that the event matches the filters (on type, target and/or content) associated with the handler.

Implements Erebot\Interfaces\EventHandler.

Definition at line 87 of file EventHandler.php.

Erebot\EventHandler::setCallback ( \Erebot\CallableInterface  $callback)

Sets the callback associated with this handler.

Parameters
Erebot::CallableInterface$callbackThis callable object will be called whenever an event is received that matches the criteria set by this event handler's filter.

Implements Erebot\Interfaces\EventHandler.

Definition at line 65 of file EventHandler.php.

Erebot\EventHandler::setFilter ( \Erebot\Interfaces\Event\Match  $filter = null)

Sets the filter associated with this event handler.

Parameters
Erebot::Interfaces::Event::Match$filter(optional) The new filter associated with this event handler. Its criterion must sucessfully match the contents of an event for that event to trigger this event handler's callback.

Implements Erebot\Interfaces\EventHandler.

Definition at line 76 of file EventHandler.php.


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