1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PEIP\Dispatcher; |
4
|
|
|
|
5
|
|
|
namespace PEIP\Dispatcher; |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
* This file is part of the PEIP package. |
9
|
|
|
* (c) 2009-2016 Timo Michna <timomichna/yahoo.de> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/* |
16
|
|
|
* Dispatcher |
17
|
|
|
* Basic dispatcher implementation |
18
|
|
|
* |
19
|
|
|
* @author Timo Michna <timomichna/yahoo.de> |
20
|
|
|
* @package PEIP |
21
|
|
|
* @subpackage dispatcher |
22
|
|
|
* @extends \PEIP\ABS\Dispatcher\Dispatcher |
23
|
|
|
* @implements \PEIP\INF\Dispatcher\Dispatcher |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
use PEIP\Util\Test; |
27
|
|
|
|
28
|
|
|
class Dispatcher extends \PEIP\ABS\Dispatcher\Dispatcher implements |
29
|
|
|
\PEIP\INF\Dispatcher\Dispatcher, |
30
|
|
|
\PEIP\INF\Base\Plugable |
31
|
|
|
{ |
32
|
|
|
protected $listeners = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Connects a listener. |
36
|
|
|
* |
37
|
|
|
* @param callable|PEIP\INF\Handler\Handler $listener |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function connect($listener) |
42
|
|
|
{ |
43
|
|
|
Test::ensureHandler($listener); |
44
|
|
|
$this->listeners[] = $listener; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Disconnects a listener. |
49
|
|
|
* |
50
|
|
|
* @param callable|PEIP\INF\Handler\Handler $listener |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function disconnect($listener) |
55
|
|
|
{ |
56
|
|
|
Test::ensureHandler($listener); |
57
|
|
|
foreach ($this->listeners as $i => $callable) { |
58
|
|
|
if ($listener === $callable) { |
59
|
|
|
unset($this->listeners[$i]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Disconnects all listeners. |
66
|
|
|
* |
67
|
|
|
* @param callable|PEIP\INF\Handler\Handler $listener |
|
|
|
|
68
|
|
|
* |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
public function disconnectAll() |
72
|
|
|
{ |
73
|
|
|
$this->listeners = []; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* returns wether any listeners are registered. |
78
|
|
|
* |
79
|
|
|
* @return bool wether any listeners are registered |
80
|
|
|
*/ |
81
|
|
|
public function hasListeners() |
82
|
|
|
{ |
83
|
|
|
return (bool) count($this->listeners); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* notifies all listeners on a subject. |
88
|
|
|
* |
89
|
|
|
* @param mixed $subject the subject |
90
|
|
|
* |
91
|
|
|
* @return void |
92
|
|
|
*/ |
93
|
|
View Code Duplication |
public function notify($subject) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$res = null; |
96
|
|
|
if ($this->hasListeners()) { |
97
|
|
|
$res = self::doNotify($this->getListeners(), $subject); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $res; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* notifies all listeners on a subject until one returns a boolean true value. |
105
|
|
|
* |
106
|
|
|
* @param mixed $subject the subject |
107
|
|
|
* |
108
|
|
|
* @return \PEIP\INF\Handler\Handler the listener which returned a boolean true value |
109
|
|
|
*/ |
110
|
|
|
public function notifyUntil($subject) |
111
|
|
|
{ |
112
|
|
|
if ($this->hasListeners()) { |
113
|
|
|
$res = self::doNotifyUntil($this->getListeners(), $subject); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $res; |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* returns all listeners. |
121
|
|
|
* |
122
|
|
|
* @return array the listeners |
123
|
|
|
*/ |
124
|
|
|
public function getListeners() |
125
|
|
|
{ |
126
|
|
|
return $this->listeners; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
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.