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

Class used to represent anything that is callable. More...

+ Inheritance diagram for Erebot\CallableWrapper:

Public Member Functions

 __toString ()
 
- Public Member Functions inherited from Erebot\CallableInterface
 __invoke ()
 

Static Public Member Functions

static initialize ()
 
static represent ($callable)
 
static wrap ($callable)
 

Protected Member Functions

 __construct ($callable)
 

Protected Attributes

 $callable
 Inner callable object, as used by PHP.
 
 $representation
 Human representation of the inner callable.
 

Detailed Description

Class used to represent anything that is callable.

This class can represent a wild range of callable items supported by PHP (functions, lambdas, methods, closures, etc.).

Definition at line 30 of file CallableWrapper.php.

Constructor & Destructor Documentation

Erebot\CallableWrapper::__construct (   $callable)
protected

Constructs a new callable object, abstracting differences between the different constructs PHP supports.

Parameters
mixed$callableA callable item. It must be compatible with the PHP callback pseudo-type.
string$representationHuman readable representation of the callable.
See also
More information on the callback pseudo-type can be found here: http://php.net/language.pseudo-types.php#language.types.callback

Definition at line 54 of file CallableWrapper.php.

Member Function Documentation

Erebot\CallableWrapper::__toString ( )

Returns a human readable representation of this callable.

For functions (including anonymous functions created with create_function()), this is a string containing the name of that function. For methods and objects that implement the __invoke() magic method (including Closures), this is a string of the form "ClassName::methodName".

Return values
stringHuman readable representation of this callable.

Definition at line 72 of file CallableWrapper.php.

static Erebot\CallableWrapper::initialize ( )
static

Initialize the wrapper.

Parameters
bool$existing(optional) Whether to inject the wrapper inside existing namespaces. You don't need to pass this argument: the wrapper already does so internally when needed.
Note
This method must be called before using any of the wrapper's other methods. It registers an autoloader that automatically adds a "callable" typehint to namespaces on PHP 5.3.x when a new class/interface is autoloaded.
This method needs to be called only once, unless you're using functions or requiring/including files manually, in which case it is advisable to call this method periodically (eg. using register_tick_function() and declare(ticks=N) with an adequate value for N depending on your code).

Definition at line 180 of file CallableWrapper.php.

Referenced by Erebot\Patches\patch().

static Erebot\CallableWrapper::represent (   $callable)
static

Returns a human readable representation of a callable.

For functions (including anonymous functions created with create_function()), this is a string containing the name of that function. For methods and objects that implement the __invoke() magic method (including Closures), this is a string of the form "ClassName::methodName".

Parameters
mixed$callableCallable piece of code to describe.
Return values
stringHuman readable representation of the callable.
Exceptions
InvalidArgumentExceptionThe given argument does not represent a callable piece of code.

Definition at line 256 of file CallableWrapper.php.

static Erebot\CallableWrapper::wrap (   $callable)
static

Wraps an existing callable piece of code.

Parameters
mixed$callableCallable piece of code to wrap.
Return values
Erebot::CallableInterfaceAn object of a class implementing the Erebot::CallableInterface is returned. The precise type of the object will usually vary between calls as new types are created on-the-fly if needed.

Definition at line 90 of file CallableWrapper.php.

Referenced by Erebot\Config\Proxy\parseBool(), Erebot\Config\Proxy\parseInt(), Erebot\Config\Proxy\parseReal(), Erebot\Config\Proxy\parseString(), and Erebot\Module\Base\reloadModule().


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