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

An implementation of timers. More...

+ Inheritance diagram for Erebot\Timer:

Public Member Functions

 __construct (\Erebot\CallableInterface $callback, $delay, $repeat, $args=array())
 
 __destruct ()
 Destroys the timer.
 
 activate ()
 
 getArgs ()
 
 getCallback ()
 
 getDelay ()
 
 getRepetition ()
 
 getStream ()
 
 reset ()
 
 setArgs (array $args)
 
 setCallback (\Erebot\CallableInterface $callback)
 
 setRepetition ($repeat)
 

Protected Member Functions

 cleanup ()
 

Protected Attributes

 $args
 Additional arguments to call the callback function with.
 
 $callback
 Function or method to call when the timer expires.
 
 $delay
 Delay after which the timer will expire.
 
 $handle
 A file descriptor which is used to implement timers.
 
 $repeat
 Number of times the timer will be reset.
 
 $resource
 Internal resource used to implement timers.
 

Static Protected Attributes

static $binary = null
 Path to the PHP binary to use to launch timers.
 
static $windowsStrategy = 0
 Activate a special strategy for Windows.
 

Detailed Description

An implementation of timers.

Definition at line 27 of file Timer.php.

Constructor & Destructor Documentation

Erebot\Timer::__construct ( \Erebot\CallableInterface  $callback,
  $delay,
  $repeat,
  $args = array() 
)

Creates a new timer, set off to call the given callback (optionally, repeatedly) when the associated delay passed.

Parameters
Erebot::CallableInterface$callbackThe callback to call when the timer expires. See http://php.net/manual/en/language.pseudo-types.php for acceptable callback values.
number$delayThe number of seconds to wait for before calling the callback. This may be a float/double or an int, but the implementation may choose to round it up to the nearest integer if sub-second precision is impossible to get (eg. on Windows).
bool | int$repeatEither a boolean indicating whether the callback should be called repeatedly every $delay seconds or just once, or an integer specifying the exact number of times the callback will be called.
array$args(optional) Additional arguments to pass to the callback when it is called.

Definition at line 79 of file Timer.php.

Member Function Documentation

Erebot\Timer::activate ( )

Calls the callback.

Warning
This method is called automatically and should not be called manually. Calling it manually may lead to unexpected results.

Implements Erebot\TimerInterface.

Definition at line 258 of file Timer.php.

Erebot\Timer::cleanup ( )
protected

Performs cleanup duties so that no traces of this timer having ever been used remain.

Definition at line 123 of file Timer.php.

Erebot\Timer::getArgs ( )

Returns an array of additional arguments to pass to the callback.

Return values
arrayArguments that will be passed to the callback.
Note
The first argument passed to the callback is ALWAYS the timer event that timed out, but the timer IS NOT considered as a part of the arguments for the purpose of this method and therefore will be missing from the array it returns.

Implements Erebot\TimerInterface.

Definition at line 152 of file Timer.php.

Erebot\Timer::getCallback ( )

Returns a reference to the callback associated with this timer.

Return values
callbackThe callback for this timer.

Implements Erebot\TimerInterface.

Definition at line 142 of file Timer.php.

Erebot\Timer::getDelay ( )

Returns the delay after which the callback will be called. This is the original value given to the timer during construction, and it is not updated live as time passes by.

Return values
numberThe original delay for this timer, as decided at construction time.

Implements Erebot\TimerInterface.

Definition at line 157 of file Timer.php.

Erebot\Timer::getRepetition ( )

Returns the number of timer this timer will be restarted.

Return values
intReturns the repetition state of the timer.

Implements Erebot\TimerInterface.

Definition at line 162 of file Timer.php.

Erebot\Timer::getStream ( )

Returns the underlying stream used by the implementation to create timers.

Return values
streamThe underlying PHP stream.

Implements Erebot\TimerInterface.

Definition at line 184 of file Timer.php.

Erebot\Timer::reset ( )

(Re)starts the timer.

Postcondition
The timer is started. The repetition counter is decremented as necessary.
Warning
It is the responsability of whoever uses the timer to restart it when needed.

Implements Erebot\TimerInterface.

Definition at line 189 of file Timer.php.

Erebot\Timer::setArgs ( array  $args)

Sets the arguments for this timer.

Whenever this timer fires, its callback will be called with these arguments.

Parameters
array$argsAn array containing the parameters to pass to this timer's callback whenever it fires. The parameters will be passed in the same order they appear in this array.

Implements Erebot\TimerInterface.

Definition at line 147 of file Timer.php.

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

Sets the callback associated with this timer.

Parameters
Erebot::CallableInterface$callbackThis callable object will be called whenever the timer fires.

Implements Erebot\TimerInterface.

Definition at line 137 of file Timer.php.

Erebot\Timer::setRepetition (   $repeat)

Changes the number of times this timer can go off.

Parameters
bool | int$repeatCan be either:
  • An integer indicating the number of times the timer will be triggered (with any negative value being treated as positive infinity).
  • A boolean which indicates that the timer should call the callback repeatedly (true, same as -1) or just once (false, same as 1).

Implements Erebot\TimerInterface.

Definition at line 167 of file Timer.php.


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