7 * This is a virtual class.
9 * Subclases of WikiCallback can be used to represent either
10 * global function callbacks, or object method callbacks.
12 * @see WikiFunctionCb, WikiMethodCb.
17 * Convert from Pear-style callback specification to a WikiCallback.
19 * This is a static member function.
21 * @param $pearCb mixed
22 * For a global function callback, $pearCb should be a string containing
23 * the name of the function.
24 * For an object method callback, $pearCb should be a array of length two:
25 * the first element should contain (a reference to) the object, the second
26 * element should be a string containing the name of the method to be invoked.
27 * @return object Returns the appropriate subclass of WikiCallback.
30 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.
49 return $this->call_array(func_get_args());
53 * Call callback (with args in array).
55 * @param $args array Contains the arguments to be passed to the callback.
56 * @return mixed The return value of the callback.
57 * @see call_user_func_array.
60 function call_array ($args) {
61 trigger_error('pure virtual', E_USER_ERROR);
65 * Convert to Pear callback.
67 * @return string The name of the callback function.
68 * (This value is suitable for passing as the callback parameter
69 * to a number of different Pear functions and methods.)
73 trigger_error('pure virtual', E_USER_ERROR);
78 * Global function callback.
86 * @param $functionName string Name of global function to call.
89 function WikiFunctionCb ($functionName) {
90 $this->functionName = $functionName;
93 function call_array ($args) {
94 return call_user_func_array($this->functionName, $args);
98 return $this->functionName;
103 * Object Method Callback.
111 * @param $object object Object on which to invoke method.
112 * @param $methodName string Name of method to call.
115 function WikiMethodCb(&$object, $methodName) {
116 $this->object = &$object;
117 $this->methodName = $methodName;
120 function call_array ($args) {
121 $method = &$this->methodName;
122 return call_user_func_array(array(&$this->object, $method), $args);
125 function toPearCb() {
126 return array($this->object, $this->methodName);
131 * Anonymous function callback.
133 class WikiAnonymousCb
139 * @param $args string Argument declarations
140 * @param $code string Function body
141 * @see create_function().
144 function WikiAnonymousCb ($args, $code) {
145 $this->function = create_function($args, $code);
148 function call_array ($args) {
149 return call_user_func_array($this->function, $args);
152 function toPearCb() {
153 trigger_error("Can't convert WikiAnonymousCb to Pear callback",
162 // c-hanging-comment-ender-p: nil
163 // indent-tabs-mode: nil