This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Event Emitter (HEAVILY based on evenement/evenement) |
||
4 | * |
||
5 | * PHP version 5 |
||
6 | * |
||
7 | * Copyright (C) 2016 Jake Johns |
||
8 | * |
||
9 | * This software may be modified and distributed under the terms |
||
10 | * of the MIT license. See the LICENSE file for details. |
||
11 | * |
||
12 | * @category Emitter |
||
13 | * @package Jnjxp\Event |
||
14 | * @author Jake Johns <[email protected]> |
||
15 | * @copyright 2016 Jake Johns |
||
16 | * @license http://jnj.mit-license.org/2016 MIT License |
||
17 | * @link https://github.com/jnjxp/jnjxp.event |
||
18 | */ |
||
19 | |||
20 | namespace Jnjxp\Event; |
||
21 | |||
22 | /** |
||
23 | * Emitter |
||
24 | * |
||
25 | * @category Emitter |
||
26 | * @package Jnjxp\Event |
||
27 | * @author Jake Johns <[email protected]> |
||
28 | * @license http://jnj.mit-license.org/ MIT License |
||
29 | * @link https://github.com/jnjxp/jnjxp.event |
||
30 | */ |
||
31 | class Emitter |
||
32 | { |
||
33 | /** |
||
34 | * Listener specs |
||
35 | * |
||
36 | * @var array |
||
37 | * |
||
38 | * @access protected |
||
39 | */ |
||
40 | protected $listeners = []; |
||
41 | |||
42 | /** |
||
43 | * Resolver |
||
44 | * |
||
45 | * @var callable |
||
46 | * |
||
47 | * @access protected |
||
48 | */ |
||
49 | protected $resolver; |
||
50 | |||
51 | /** |
||
52 | * __construct |
||
53 | * |
||
54 | * @param callable $resolver spec resolver |
||
55 | * |
||
56 | * @access public |
||
57 | */ |
||
58 | 16 | public function __construct(callable $resolver = null) |
|
59 | { |
||
60 | 16 | $this->resolver = $resolver; |
|
61 | 16 | } |
|
62 | |||
63 | /** |
||
64 | * Add Listener to event |
||
65 | * |
||
66 | * @param string $event name of event |
||
67 | * @param mixed $listener listener spec |
||
68 | * |
||
69 | * @return null |
||
70 | * |
||
71 | * @access public |
||
72 | * |
||
73 | * @SuppressWarnings(PHPMD.ShortMethodName) |
||
74 | */ |
||
75 | 15 | public function on($event, $listener) |
|
76 | { |
||
77 | 15 | if (!isset($this->listeners[$event])) { |
|
78 | 15 | $this->listeners[$event] = []; |
|
79 | } |
||
80 | 15 | $this->listeners[$event][] = $listener; |
|
81 | 15 | } |
|
82 | |||
83 | /** |
||
84 | * Add one time listener |
||
85 | * |
||
86 | * @param string $event name of event |
||
87 | * @param mixed $listener listener spec |
||
88 | * |
||
89 | * @return null |
||
90 | * |
||
91 | * @access public |
||
92 | */ |
||
93 | public function once($event, $listener) |
||
94 | { |
||
95 | 2 | $onceListener = function () use (&$onceListener, $event, $listener) { |
|
96 | 2 | $this->removeListener($event, $onceListener); |
|
97 | 2 | $listener = $this->resolve($listener); |
|
0 ignored issues
–
show
|
|||
98 | 2 | call_user_func_array($listener, func_get_args()); |
|
99 | 2 | }; |
|
100 | 2 | $this->on($event, $onceListener); |
|
101 | 2 | } |
|
102 | |||
103 | /** |
||
104 | * Remove listener |
||
105 | * |
||
106 | * @param string $event name of event |
||
107 | * @param mixed $listener listener spec |
||
108 | * |
||
109 | * @return null |
||
110 | * |
||
111 | * @access public |
||
112 | */ |
||
113 | 4 | public function removeListener($event, $listener) |
|
114 | { |
||
115 | 4 | if (isset($this->listeners[$event])) { |
|
116 | 3 | $index = array_search($listener, $this->listeners[$event], true); |
|
117 | 3 | if (false !== $index) { |
|
118 | 3 | unset($this->listeners[$event][$index]); |
|
119 | } |
||
120 | } |
||
121 | 4 | } |
|
122 | |||
123 | /** |
||
124 | * Remove all listeners |
||
125 | * |
||
126 | * @param null|string $event name of event |
||
127 | * |
||
128 | * @return null |
||
129 | * |
||
130 | * @access public |
||
131 | */ |
||
132 | 3 | public function removeAllListeners($event = null) |
|
133 | { |
||
134 | 3 | if ($event !== null) { |
|
135 | 2 | unset($this->listeners[$event]); |
|
136 | } else { |
||
137 | 1 | $this->listeners = []; |
|
138 | } |
||
139 | 3 | } |
|
140 | |||
141 | /** |
||
142 | * Get listeners for event |
||
143 | * |
||
144 | * @param string $event event anme |
||
145 | * |
||
146 | * @return array |
||
147 | * |
||
148 | * @access public |
||
149 | */ |
||
150 | 13 | public function listeners($event) |
|
151 | { |
||
152 | 13 | return isset($this->listeners[$event]) ? $this->listeners[$event] : []; |
|
153 | } |
||
154 | |||
155 | /** |
||
156 | * Emit event signal |
||
157 | * |
||
158 | * @param string $event name of event |
||
159 | * @param array $arguments event arguments |
||
160 | * |
||
161 | * @return null |
||
162 | * |
||
163 | * @access public |
||
164 | */ |
||
165 | 13 | public function emit($event, array $arguments = []) |
|
166 | { |
||
167 | 13 | foreach ($this->listeners($event) as $listener) { |
|
168 | 9 | $listener = $this->resolve($listener); |
|
169 | 9 | call_user_func_array($listener, $arguments); |
|
170 | } |
||
171 | 13 | } |
|
172 | |||
173 | /** |
||
174 | * Resolve |
||
175 | * |
||
176 | * @param mixed $spec listener spec |
||
177 | * |
||
178 | * @return mixed |
||
179 | * |
||
180 | * @access protected |
||
181 | */ |
||
182 | 9 | protected function resolve($spec) |
|
183 | { |
||
184 | 9 | if (! $this->resolver) { |
|
185 | 8 | return $spec; |
|
186 | } |
||
187 | |||
188 | 1 | return call_user_func($this->resolver, $spec); |
|
189 | } |
||
190 | } |
||
191 |
It seems like you are assigning to a variable which was imported through a
use
statement which was not imported by reference.For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.
Change not visible in outer-scope
Change visible in outer-scope