1 | <?php |
||
11 | class Event |
||
12 | { |
||
13 | /** @var string READONLY event name, objects must register against this name to see the event */ |
||
14 | public $name = ''; |
||
15 | /** @var mixed|null READWRITE data relevant to the event, no standardised format, refer to event docs */ |
||
16 | public $data = null; |
||
17 | /** |
||
18 | * @var mixed|null READWRITE the results of the event action, only relevant in "_AFTER" advise |
||
19 | * event handlers may modify this if they are preventing the default action |
||
20 | * to provide the after event handlers with event results |
||
21 | */ |
||
22 | public $result = null; |
||
23 | /** @var bool READONLY if true, event handlers can prevent the events default action */ |
||
24 | public $canPreventDefault = true; |
||
25 | |||
26 | /** @var bool whether or not to carry out the default action associated with the event */ |
||
27 | protected $runDefault = true; |
||
28 | /** @var bool whether or not to continue propagating the event to other handlers */ |
||
29 | protected $mayContinue = true; |
||
30 | |||
31 | /** |
||
32 | * event constructor |
||
33 | * |
||
34 | * @param string $name |
||
35 | * @param mixed $data |
||
36 | */ |
||
37 | public function __construct($name, &$data) |
||
43 | |||
44 | /** |
||
45 | * @return string |
||
46 | */ |
||
47 | public function __toString() |
||
51 | |||
52 | /** |
||
53 | * advise all registered BEFORE handlers of this event |
||
54 | * |
||
55 | * if these methods are used by functions outside of this object, they must |
||
56 | * properly handle correct processing of any default action and issue an |
||
57 | * advise_after() signal. e.g. |
||
58 | * $evt = new dokuwiki\Plugin\Doku_Event(name, data); |
||
59 | * if ($evt->advise_before(canPreventDefault) { |
||
60 | * // default action code block |
||
61 | * } |
||
62 | * $evt->advise_after(); |
||
63 | * unset($evt); |
||
64 | * |
||
65 | * @param bool $enablePreventDefault |
||
66 | * @return bool results of processing the event, usually $this->runDefault |
||
67 | */ |
||
68 | public function advise_before($enablePreventDefault = true) |
||
82 | |||
83 | /** |
||
84 | * advise all registered AFTER handlers of this event |
||
85 | * |
||
86 | * @param bool $enablePreventDefault |
||
|
|||
87 | * @see advise_before() for details |
||
88 | */ |
||
89 | public function advise_after() |
||
102 | |||
103 | /** |
||
104 | * trigger |
||
105 | * |
||
106 | * - advise all registered (<event>_BEFORE) handlers that this event is about to take place |
||
107 | * - carry out the default action using $this->data based on $enablePrevent and |
||
108 | * $this->_default, all of which may have been modified by the event handlers. |
||
109 | * - advise all registered (<event>_AFTER) handlers that the event has taken place |
||
110 | * |
||
111 | * @param null|callable $action |
||
112 | * @param bool $enablePrevent |
||
113 | * @return mixed $event->results |
||
114 | * the value set by any <event>_before or <event> handlers if the default action is prevented |
||
115 | * or the results of the default action (as modified by <event>_after handlers) |
||
116 | * or NULL no action took place and no handler modified the value |
||
117 | */ |
||
118 | public function trigger($action = null, $enablePrevent = true) |
||
140 | |||
141 | /** |
||
142 | * stopPropagation |
||
143 | * |
||
144 | * stop any further processing of the event by event handlers |
||
145 | * this function does not prevent the default action taking place |
||
146 | */ |
||
147 | public function stopPropagation() |
||
151 | |||
152 | /** |
||
153 | * may the event propagate to the next handler? |
||
154 | * |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function mayPropagate() |
||
161 | |||
162 | /** |
||
163 | * preventDefault |
||
164 | * |
||
165 | * prevent the default action taking place |
||
166 | */ |
||
167 | public function preventDefault() |
||
171 | |||
172 | /** |
||
173 | * should the default action be executed? |
||
174 | * |
||
175 | * @return bool |
||
176 | */ |
||
177 | public function mayRunDefault() |
||
181 | |||
182 | /** |
||
183 | * Convenience method to trigger an event |
||
184 | * |
||
185 | * Creates, triggers and destroys an event in one go |
||
186 | * |
||
187 | * @param string $name name for the event |
||
188 | * @param mixed $data event data |
||
189 | * @param callable $action (optional, default=NULL) default action, a php callback function |
||
190 | * @param bool $canPreventDefault (optional, default=true) can hooks prevent the default action |
||
191 | * |
||
192 | * @return mixed the event results value after all event processing is complete |
||
193 | * by default this is the return value of the default action however |
||
194 | * it can be set or modified by event handler hooks |
||
195 | */ |
||
196 | static public function createAndTrigger($name, &$data, $action = null, $canPreventDefault = true) |
||
201 | } |
||
202 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.