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.
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.
29 function callback($pearCb)
31 if (is_string($pearCb))
32 return new WikiFunctionCb($pearCb);
33 else if (is_array($pearCb)) {
34 list($object, $method) = $handler;
35 return new WikiMethodCb($object, $method);
37 trigger_error("WikiCallback::new: bad arg", E_USER_ERROR);
43 * @param ? mixed This method takes a variable number of arguments (zero or more).
44 * The callback function is called with the specified arguments.
45 * @return mixed The return value of the callback.
50 return $this->call_array(func_get_args());
54 * Call callback (with args in array).
56 * @param $args array Contains the arguments to be passed to the callback.
57 * @return mixed The return value of the callback.
58 * @see call_user_func_array.
61 function call_array($args)
63 trigger_error('pure virtual', E_USER_ERROR);
67 * Convert to Pear callback.
69 * @return string The name of the callback function.
70 * (This value is suitable for passing as the callback parameter
71 * to a number of different Pear functions and methods.)
76 trigger_error('pure virtual', E_USER_ERROR);
81 * Global function callback.
89 * @param $functionName string Name of global function to call.
92 function WikiFunctionCb($functionName)
94 $this->functionName = $functionName;
97 function call_array($args)
99 return call_user_func_array($this->functionName, $args);
104 return $this->functionName;
109 * Object Method Callback.
117 * @param $object object Object on which to invoke method.
118 * @param $methodName string Name of method to call.
121 function WikiMethodCb(&$object, $methodName)
123 $this->object = &$object;
124 $this->methodName = $methodName;
127 function call_array($args)
129 $method = &$this->methodName;
130 return call_user_func_array(array(&$this->object, $method), $args);
135 return array($this->object, $this->methodName);
140 * Anonymous function callback.
142 class WikiAnonymousCb
148 * @param $args string Argument declarations
149 * @param $code string Function body
150 * @see create_function().
153 function WikiAnonymousCb($args, $code)
155 $this->function = create_function($args, $code);
158 function call_array($args)
160 return call_user_func_array($this->function, $args);
165 trigger_error("Can't convert WikiAnonymousCb to Pear callback",
174 // c-hanging-comment-ender-p: nil
175 // indent-tabs-mode: nil