6 * This is a virtual class.
8 * Subclases of WikiCallback can be used to represent either
9 * global function callbacks, or object method callbacks.
11 * @see WikiFunctionCb, WikiMethodCb.
13 abstract class WikiCallback
16 * Convert from Pear-style callback specification to a WikiCallback.
18 * This is a static member function.
20 * @param $pearCb mixed
21 * For a global function callback, $pearCb should be a string containing
22 * the name of the function.
23 * For an object method callback, $pearCb should be a array of length two:
24 * the first element should contain (a reference to) the object, the second
25 * element should be a string containing the name of the method to be invoked.
26 * @return object Returns the appropriate subclass of WikiCallback.
28 public function callback($pearCb)
30 if (is_string($pearCb))
31 return new WikiFunctionCb($pearCb);
32 else if (is_array($pearCb)) {
33 list($object, $method) = $handler;
34 return new WikiMethodCb($object, $method);
36 trigger_error("WikiCallback::new: bad arg", E_USER_ERROR);
42 * @param ? mixed This method takes a variable number of arguments (zero or more).
43 * The callback function is called with the specified arguments.
44 * @return mixed The return value of the callback.
46 public function call()
48 return $this->call_array(func_get_args());
52 * Call callback (with args in array).
54 * @param $args array Contains the arguments to be passed to the callback.
55 * @return mixed The return value of the callback.
56 * @see call_user_func_array.
58 abstract public function call_array($args);
61 * Convert to Pear callback.
63 * @return string The name of the callback function.
64 * (This value is suitable for passing as the callback parameter
65 * to a number of different Pear functions and methods.)
67 abstract public function toPearCb();
71 * Global function callback.
77 * @param $functionName string Name of global function to call.
79 public function __construct($functionName)
81 $this->functionName = $functionName;
84 function call_array($args)
86 return call_user_func_array($this->functionName, $args);
91 return $this->functionName;
96 * Object Method Callback.
102 * @param $object object Object on which to invoke method.
103 * @param $methodName string Name of method to call.
105 function __construct(&$object, $methodName)
107 $this->object = &$object;
108 $this->methodName = $methodName;
111 function call_array($args)
113 $method = &$this->methodName;
114 return call_user_func_array(array(&$this->object, $method), $args);
119 return array($this->object, $this->methodName);
124 * Anonymous function callback.
126 class WikiAnonymousCb
130 * @param $args string Argument declarations
131 * @param $code string Function body
132 * @see create_function().
134 function __construct($args, $code)
136 $this->function = create_function($args, $code);
139 function call_array($args)
141 return call_user_func_array($this->function, $args);
146 trigger_error("Can't convert WikiAnonymousCb to Pear callback",
155 // c-hanging-comment-ender-p: nil
156 // indent-tabs-mode: nil