]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiCallback.php
Remove Width and Height preferences modification in Edit Toolbar
[SourceForge/phpwiki.git] / lib / WikiCallback.php
1 <?php
2
3 /**
4  * A callback
5  *
6  * This is a virtual class.
7  *
8  * Subclases of WikiCallback can be used to represent either
9  * global function callbacks, or object method callbacks.
10  *
11  * @see WikiFunctionCb, WikiMethodCb.
12  */
13 abstract class WikiCallback
14 {
15     /**
16      * Call callback.
17      *
18      * @param ? mixed This method takes a variable number of arguments (zero or more).
19      * The callback function is called with the specified arguments.
20      * @return mixed The return value of the callback.
21      */
22     public function call()
23     {
24         return $this->call_array(func_get_args());
25     }
26
27     /**
28      * Call callback (with args in array).
29      *
30      * @param $args array Contains the arguments to be passed to the callback.
31      * @return mixed The return value of the callback.
32      * @see call_user_func_array.
33      */
34     abstract public function call_array($args);
35
36     /**
37      * Convert to Pear callback.
38      *
39      * @return string The name of the callback function.
40      *  (This value is suitable for passing as the callback parameter
41      *   to a number of different Pear functions and methods.)
42      */
43     abstract public function toPearCb();
44 }
45
46 /**
47  * Global function callback.
48  */
49 class WikiFunctionCb
50     extends WikiCallback
51 {
52     /**
53      * @param string $functionName Name of global function to call.
54      */
55     public function __construct($functionName)
56     {
57         $this->functionName = $functionName;
58     }
59
60     function call_array($args)
61     {
62         return call_user_func_array($this->functionName, $args);
63     }
64
65     function toPearCb()
66     {
67         return $this->functionName;
68     }
69 }
70
71 /**
72  * Object Method Callback.
73  */
74 class WikiMethodCb
75     extends WikiCallback
76 {
77     /**
78      * @param object $object Object on which to invoke method.
79      * @param string $methodName Name of method to call.
80      */
81     function __construct(&$object, $methodName)
82     {
83         $this->object = &$object;
84         $this->methodName = $methodName;
85     }
86
87     function call_array($args)
88     {
89         $method = &$this->methodName;
90         return call_user_func_array(array(&$this->object, $method), $args);
91     }
92
93     function toPearCb()
94     {
95         return array($this->object, $this->methodName);
96     }
97 }
98
99 /**
100  * Anonymous function callback.
101  */
102 class WikiAnonymousCb
103     extends WikiCallback
104 {
105     /**
106      * @param string $args Argument declarations
107      * @param string $code Function body
108      * @see create_function().
109      */
110     function __construct($args, $code)
111     {
112         $this->function = create_function($args, $code);
113     }
114
115     function call_array($args)
116     {
117         return call_user_func_array($this->function, $args);
118     }
119
120     function toPearCb()
121     {
122         trigger_error("Can't convert WikiAnonymousCb to Pear callback",
123             E_USER_ERROR);
124     }
125 }
126
127 // Local Variables:
128 // mode: php
129 // tab-width: 8
130 // c-basic-offset: 4
131 // c-hanging-comment-ender-p: nil
132 // indent-tabs-mode: nil
133 // End: