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) {
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.
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.
59 function call_array ($args) {
60 trigger_error('pure virtual', E_USER_ERROR);
64 * Convert to Pear callback.
66 * @return string The name of the callback function.
67 * (This value is suitable for passing as the callback parameter
68 * to a number of different Pear functions and methods.)
72 trigger_error('pure virtual', E_USER_ERROR);
77 * Global function callback.
85 * @param $functionName string Name of global function to call.
88 function WikiFunctionCb ($functionName) {
89 $this->functionName = $functionName;
92 function call_array ($args) {
93 return call_user_func_array($this->functionName, $args);
97 return $this->functionName;
102 * Object Method Callback.
110 * @param $object object Object on which to invoke method.
111 * @param $methodName string Name of method to call.
114 function WikiMethodCb(&$object, $methodName) {
115 $this->object = &$object;
116 $this->methodName = $methodName;
119 function call_array ($args) {
120 $method = &$this->methodName;
121 return call_user_func_array(array(&$this->object, $method), $args);
124 function toPearCb() {
125 return array($this->object, $this->methodName);
130 * Anonymous function callback.
132 class WikiAnonymousCb
138 * @param $args string Argument declarations
139 * @param $code string Function body
140 * @see create_function().
143 function WikiAnonymousCb ($args, $code) {
144 $this->function = create_function($args, $code);
147 function call_array ($args) {
148 return call_user_func_array($this->function, $args);
151 function toPearCb() {
152 trigger_error("Can't convert WikiAnonymousCb to Pear callback",
161 // c-hanging-comment-ender-p: nil
162 // indent-tabs-mode: nil