1 | <?php |
||
10 | final class Provider implements ListenerProviderInterface |
||
11 | { |
||
12 | private $listeners = []; |
||
13 | |||
14 | public function getListenersForEvent(object $event): iterable |
||
33 | |||
34 | /** |
||
35 | * Attaches listener to corresponding event based on the type-hint used for the event argument. |
||
36 | * |
||
37 | * Method signature should be the following: |
||
38 | * |
||
39 | * ``` |
||
40 | * function (MyEvent $event): void |
||
41 | * ``` |
||
42 | * |
||
43 | * Any callable could be used be it a closure, invokable object or array referencing a class or object. |
||
44 | * |
||
45 | * @param callable $listener |
||
46 | */ |
||
47 | public function attach(callable $listener): void |
||
51 | |||
52 | /** |
||
53 | * Detach all event handlers registered for an interface |
||
54 | * |
||
55 | * @param string $interface |
||
56 | */ |
||
57 | public function detach(string $interface): void |
||
61 | |||
62 | /** |
||
63 | * Derives the interface type of the first argument of a callable. |
||
64 | * |
||
65 | * @param callable $callable The callable for which we want the parameter type. |
||
66 | * @return string The interface the parameter is type hinted on. |
||
67 | */ |
||
68 | private function getParameterType(callable $callable): string |
||
105 | |||
106 | /** |
||
107 | * Determines if a callable represents a function. |
||
108 | * |
||
109 | * Or at least a reasonable approximation, since a function name may not be defined yet. |
||
110 | * |
||
111 | * @param callable $callable |
||
112 | * @return True if the callable represents a function, false otherwise. |
||
113 | */ |
||
114 | private function isFunctionCallable(callable $callable): bool |
||
119 | |||
120 | /** |
||
121 | * Determines if a callable represents a closure/anonymous function. |
||
122 | * |
||
123 | * @param callable $callable |
||
124 | * @return True if the callable represents a closure object, false otherwise. |
||
125 | */ |
||
126 | private function isClosureCallable(callable $callable): bool |
||
130 | |||
131 | /** |
||
132 | * @param callable $callable |
||
133 | * @return True if the callable represents an invokable object, false otherwise. |
||
134 | */ |
||
135 | private function isInvokable(callable $callable): bool |
||
139 | |||
140 | /** |
||
141 | * Determines if a callable represents a method on an object. |
||
142 | * |
||
143 | * @param callable $callable |
||
144 | * @return True if the callable represents a method object, false otherwise. |
||
145 | */ |
||
146 | private function isObjectCallable(callable $callable): bool |
||
150 | |||
151 | /** |
||
152 | * Determines if a callable represents a static class method. |
||
153 | * |
||
154 | * The parameter here is untyped so that this method may be called with an |
||
155 | * array that represents a class name and a non-static method. The routine |
||
156 | * to determine the parameter type is identical to a static method, but such |
||
157 | * an array is still not technically callable. Omitting the parameter type here |
||
158 | * allows us to use this method to handle both cases. |
||
159 | * |
||
160 | * Note that this method must therefore be the first in the switch statement |
||
161 | * above, or else subsequent calls will break as the array is not going to satisfy |
||
162 | * the callable type hint but it would pass `is_callable()`. Because PHP. |
||
163 | * |
||
164 | * @param callable $callable |
||
165 | * @return True if the callable represents a static method, false otherwise. |
||
166 | */ |
||
167 | private function isClassCallable($callable): bool |
||
171 | } |
||
172 |