@@ -265,7 +265,7 @@ |
||
265 | 265 | // scaffold if not exist |
266 | 266 | if (!$this->hasSubscribers($eventName)) { |
267 | 267 | $this->subscribers[$eventName] = [ |
268 | - [ // insert positions |
|
268 | + [// insert positions |
|
269 | 269 | self::PRIORITY_URGENT => 1, |
270 | 270 | self::PRIORITY_HIGHEST => 1, |
271 | 271 | self::PRIORITY_HIGH => 1, |
@@ -438,7 +438,7 @@ |
||
438 | 438 | * |
439 | 439 | * @internal |
440 | 440 | * |
441 | - * @param mixed $needle The value to be searched for |
|
441 | + * @param callable $needle The value to be searched for |
|
442 | 442 | * @param array $haystack The array |
443 | 443 | * |
444 | 444 | * @return int|bool The top-level key containing the needle if found, false otherwise |
@@ -108,7 +108,8 @@ |
||
108 | 108 | } else { |
109 | 109 | $autohandlers = []; |
110 | 110 | |
111 | - foreach ($methods as $method) { // slow |
|
111 | + foreach ($methods as $method) { |
|
112 | +// slow |
|
112 | 113 | //extract the event name from the method name |
113 | 114 | $eventName = lcfirst(substr($method->name, 2)); |
114 | 115 |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | // filter out any that don't begin with "on" |
100 | 100 | $methods = array_filter( |
101 | 101 | $methods, |
102 | - function (\ReflectionMethod $m) { |
|
102 | + function(\ReflectionMethod $m) { |
|
103 | 103 | return (strpos($m->name, 'on') === 0); |
104 | 104 | } |
105 | 105 | ); // slow, both array_filter and closure |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | // filter out auto-handlers so that a subsequent call to subscribe() |
156 | 156 | // works predictably |
157 | - $this->handlers = array_filter($this->handlers, function ($v) { |
|
157 | + $this->handlers = array_filter($this->handlers, function($v) { |
|
158 | 158 | return (strpos($v[0][1], 'on') !== 0); |
159 | 159 | }); |
160 | 160 |
@@ -17,7 +17,8 @@ |
||
17 | 17 | */ |
18 | 18 | class Fancify extends Noair\Observer |
19 | 19 | { |
20 | - public function onCreatePost(Event $event) { |
|
20 | + public function onCreatePost(Event $event) |
|
21 | + { |
|
21 | 22 | return str_replace('border:1px solid #EEE;', |
22 | 23 | 'border:1px solid #DADADA;background:#F1F1F1;font-family:Arial;font-size:15px;', |
23 | 24 | $event->previousResult); |
@@ -47,15 +47,15 @@ |
||
47 | 47 | |
48 | 48 | public function onCreatePost(Event $event) { |
49 | 49 | $result = '<div style="padding: 9px 16px;border:1px solid #EEE;margin-bottom:16px;">' |
50 | - .'<strong>Posted by</strong> ' |
|
51 | - .$this->mediator->publish(new Event('formatUsername', $event->data['username'], $this)) |
|
52 | - .' (' |
|
53 | - .$this->mediator->publish(new Event('formatGroup', $event->data['group'], $this)) |
|
54 | - .')<br /><strong>Posted Date</strong> ' |
|
55 | - .$this->mediator->publish(new Event('formatDate', $event->data['date'], $this)) |
|
56 | - .'<br />' |
|
57 | - .$this->mediator->publish(new Event('formatMessage', $event->data['message'], $this)) |
|
58 | - .'</div>'; |
|
50 | + .'<strong>Posted by</strong> ' |
|
51 | + .$this->mediator->publish(new Event('formatUsername', $event->data['username'], $this)) |
|
52 | + .' (' |
|
53 | + .$this->mediator->publish(new Event('formatGroup', $event->data['group'], $this)) |
|
54 | + .')<br /><strong>Posted Date</strong> ' |
|
55 | + .$this->mediator->publish(new Event('formatDate', $event->data['date'], $this)) |
|
56 | + .'<br />' |
|
57 | + .$this->mediator->publish(new Event('formatMessage', $event->data['message'], $this)) |
|
58 | + .'</div>'; |
|
59 | 59 | return $result; |
60 | 60 | } |
61 | 61 | } |
@@ -16,7 +16,8 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class Formatter extends Noair\Observer |
18 | 18 | { |
19 | - public function subscribe() { |
|
19 | + public function subscribe() |
|
20 | + { |
|
20 | 21 | // This is just here for an example of explicitly-defined handlers |
21 | 22 | $this->handlers = [ |
22 | 23 | 'formatUsername' => [[$this, 'formatUsername']], |
@@ -28,24 +29,29 @@ discard block |
||
28 | 29 | return parent::subscribe(); |
29 | 30 | } |
30 | 31 | |
31 | - public function formatUsername(Event $event) { |
|
32 | + public function formatUsername(Event $event) |
|
33 | + { |
|
32 | 34 | return $event->data; |
33 | 35 | } |
34 | 36 | |
35 | - public function formatGroup(Event $event) { |
|
37 | + public function formatGroup(Event $event) |
|
38 | + { |
|
36 | 39 | return $event->data; |
37 | 40 | } |
38 | 41 | |
39 | - public function formatMessage(Event $event) { |
|
42 | + public function formatMessage(Event $event) |
|
43 | + { |
|
40 | 44 | return nl2br($event->data); |
41 | 45 | } |
42 | 46 | |
43 | - public function formatDate(Event $event) { |
|
47 | + public function formatDate(Event $event) |
|
48 | + { |
|
44 | 49 | // return date('F j, Y h:i:s A', $event->data); |
45 | 50 | return ''; |
46 | 51 | } |
47 | 52 | |
48 | - public function onCreatePost(Event $event) { |
|
53 | + public function onCreatePost(Event $event) |
|
54 | + { |
|
49 | 55 | $result = '<div style="padding: 9px 16px;border:1px solid #EEE;margin-bottom:16px;">' |
50 | 56 | .'<strong>Posted by</strong> ' |
51 | 57 | .$this->mediator->publish(new Event('formatUsername', $event->data['username'], $this)) |
@@ -17,7 +17,8 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class BetterFormatter extends Noair\Observer |
19 | 19 | { |
20 | - public function onFormatGroup(Event $event) { |
|
20 | + public function onFormatGroup(Event $event) |
|
21 | + { |
|
21 | 22 | $groupName = strtolower($event->data); |
22 | 23 | |
23 | 24 | switch ($groupName): |
@@ -35,7 +36,8 @@ discard block |
||
35 | 36 | return $groupName; |
36 | 37 | } |
37 | 38 | |
38 | - public function onFormatDate(Event $event) { |
|
39 | + public function onFormatDate(Event $event) |
|
40 | + { |
|
39 | 41 | return date('F j, Y h:i:s A T', $event->data); |
40 | 42 | } |
41 | 43 | } |
@@ -17,7 +17,8 @@ |
||
17 | 17 | */ |
18 | 18 | class FancyExamplePlugin extends Noair\Observer |
19 | 19 | { |
20 | - public function onFormatMessage(Event $event) { |
|
20 | + public function onFormatMessage(Event $event) |
|
21 | + { |
|
21 | 22 | $message = strip_tags($event->data); |
22 | 23 | $message = preg_replace('/\[b\](.+?)\[\/b\]/is', '<span style="font-weight:bold">$1</span>', $message); |
23 | 24 | $message = preg_replace('/\[u\](.+?)\[\/u\]/is', '<span style="text-decoration:underline">$1</span>', $message); |
@@ -30,7 +30,7 @@ |
||
30 | 30 | $sampleMessage = <<<HTML |
31 | 31 | Lorem [b]ipsum dolor sit amet[/b], consectetur adipiscing elit. Fusce dignissim neque vitae velit mollis, ac volutpat mauris consequat. Morbi sed arcu leo. Vestibulum dignissim, est at blandit suscipit, sapien leo [u]iaculis massa, mollis faucibus[/u] odio mauris sed risus. Integer mollis, ipsum ut efficitur lobortis, ex enim dictum felis, in mattis purus orci [b]in nulla. Nunc [u]semper mauris[/u] enim[/b], quis faucibus massa luctus quis. Sed ut malesuada magna, cursus ullamcorper augue. Curabitur orci nisl, mattis quis elementum eu, condimentum at lorem. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam ultricies tristique urna in maximus. Praesent facilisis, [url=http://github.com/DavidRockin]diam ac euismod sollicitudin[/url], eros diam consectetur est, quis egestas nisl orci vel nisl. Aenean consectetur justo non felis varius, eu fermentum mi fermentum. Ut ac dui ligula. |
32 | 32 | For more information please visit [url]http://github.com/DavidRockin[/url] |
33 | -HTML; |
|
33 | +html; |
|
34 | 34 | |
35 | 35 | |
36 | 36 | echo "With better formatting\n", |