.

CallbackCommand Class Reference
[Behaviour]

Command to invoke a callback. More...

Inheritance diagram for CallbackCommand:
CommandBase ICommand IAction ISerializable

List of all members.

Public Member Functions

  __construct ($callback, $args=array())
  execute ()
  Executes commands.
  get_name ()
  Returns title of command.

Protected Attributes

  $args
  $callback

Detailed Description

Command to invoke a callback.

This commands calls the given callback via call_user_func_array. That is: $args passed in passed in constructor must be an ampty or asssociative array.

The function called must return a Status or a string.

Example:

 Load::commands('generics/callback');
 $cmd = new CallbackCommand('fancy_func', array('left' => 100, 'right' => 50));
 $status = $cmd->execute();
 
 ...
 
 // Callback: Should return Status or anything Status->merge() accepts
 function fancy_func($left, $right) { ... } 
Author:
Gerd Riesselmann

Definition at line 27 of file callback.cmd.php.


Constructor & Destructor Documentation

CallbackCommand::__construct ( callback,
args = array()  
)

Reimplemented from CommandBase.

Definition at line 31 of file callback.cmd.php.

00031                                                                 {
00032                 $this->callback = $callback;
00033                 $this->args = $args;
00034         }

Member Function Documentation

CallbackCommand::execute (  ) 

Executes commands.

Returns:
Status

Reimplemented from CommandBase.

Definition at line 45 of file callback.cmd.php.

00045                                   {
00046                 $ret = new Status();
00047                 $callable_name = '';
00048                 if (!is_callable($this->callback, false, $callable_name)) {
00049                         throw new Exception('Callback Command could not call ' . $callable_name . '. Passed callback was: ' . serialize($this->callback)); 
00050                 }
00051                 $result = call_user_func_array($this->callback, $this->args);
00052                 $ret->merge($result);
00053                 return $ret;
00054         }
CallbackCommand::get_name (  ) 

Returns title of command.

Reimplemented from CommandBase.

Definition at line 59 of file callback.cmd.php.

00059                                    {
00060                 return 'callback';
00061         }       

Member Data Documentation

CallbackCommand::$args [protected]

Definition at line 29 of file callback.cmd.php.

CallbackCommand::$callback [protected]

Definition at line 28 of file callback.cmd.php.


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