15
15
* @since CakePHP(tm) v 2.1
16
16
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
17
17
*/
18
-
19
- App:: uses ( ' CakeEventListener ' , ' Event ' ) ;
18
+ namespace Cake \ Event ;
19
+ use Cake \ Error ;
20
20
21
21
/**
22
22
* The event manager is responsible for keeping track of event listeners and pass the correct
26
26
*
27
27
* @package Cake.Event
28
28
*/
29
- class CakeEventManager {
29
+ class EventManager {
30
30
31
31
/**
32
32
* The default priority queue value for new attached listeners
@@ -38,7 +38,7 @@ class CakeEventManager {
38
38
/**
39
39
* The globally available instance, used for dispatching events attached from any scope
40
40
*
41
- * @var CakeEventManager
41
+ * @var Cake\Event\EventManager
42
42
*/
43
43
protected static $ _generalManager = null ;
44
44
@@ -57,22 +57,22 @@ class CakeEventManager {
57
57
protected $ _isGlobal = false ;
58
58
59
59
/**
60
- * Returns the globally available instance of a CakeEventManager
60
+ * Returns the globally available instance of a Cake\Event\EventManager
61
61
* this is used for dispatching events attached from outside the scope
62
62
* other managers were created. Usually for creating hook systems or inter-class
63
63
* communication
64
64
*
65
65
* If called with a first params, it will be set as the globally available instance
66
66
*
67
- * @param CakeEventManager $manager
68
- * @return CakeEventManager the global event manager
67
+ * @param Cake\Event\EventManager $manager
68
+ * @return Cake\Event\EventManager the global event manager
69
69
*/
70
70
public static function instance ($ manager = null ) {
71
- if ($ manager instanceof CakeEventManager ) {
71
+ if ($ manager instanceof EventManager ) {
72
72
self ::$ _generalManager = $ manager ;
73
73
}
74
74
if (empty (self ::$ _generalManager )) {
75
- self ::$ _generalManager = new CakeEventManager ;
75
+ self ::$ _generalManager = new EventManager ;
76
76
}
77
77
78
78
self ::$ _generalManager ->_isGlobal = true ;
@@ -82,28 +82,28 @@ public static function instance($manager = null) {
82
82
/**
83
83
* Adds a new listener to an event. Listeners
84
84
*
85
- * @param callback|CakeEventListener $callable PHP valid callback type or instance of CakeEventListener to be called
86
- * when the event named with $eventKey is triggered. If a CakeEventListener instances is passed, then the `implementedEvents`
85
+ * @param callback|Cake\Event\EventListener $callable PHP valid callback type or instance of Cake\Event\EventListener to be called
86
+ * when the event named with $eventKey is triggered. If a Cake\Event\EventListener instances is passed, then the `implementedEvents`
87
87
* method will be called on the object to register the declared events individually as methods to be managed by this class.
88
88
* It is possible to define multiple event handlers per event name.
89
89
*
90
90
* @param string $eventKey The event unique identifier name to with the callback will be associated. If $callable
91
- * is an instance of CakeEventListener this argument will be ignored
91
+ * is an instance of Cake\Event\EventListener this argument will be ignored
92
92
*
93
93
* @param array $options used to set the `priority` and `passParams` flags to the listener.
94
94
* Priorities are handled like queues, and multiple attachments into the same priority queue will be treated in
95
95
* the order of insertion. `passParams` means that the event data property will be converted to function arguments
96
- * when the listener is called. If $called is an instance of CakeEventListener , this parameter will be ignored
96
+ * when the listener is called. If $called is an instance of Cake\Event\EventListener , this parameter will be ignored
97
97
*
98
98
* @return void
99
99
* @throws InvalidArgumentException When event key is missing or callable is not an
100
- * instance of CakeEventListener .
100
+ * instance of Cake\Event\EventListener .
101
101
*/
102
102
public function attach ($ callable , $ eventKey = null , $ options = array ()) {
103
- if (!$ eventKey && !($ callable instanceof CakeEventListener )) {
104
- throw new InvalidArgumentException (__d ('cake_dev ' , 'The eventKey variable is required ' ));
103
+ if (!$ eventKey && !($ callable instanceof EventListener )) {
104
+ throw new \ InvalidArgumentException (__d ('cake_dev ' , 'The eventKey variable is required ' ));
105
105
}
106
- if ($ callable instanceof CakeEventListener ) {
106
+ if ($ callable instanceof EventListener ) {
107
107
$ this ->_attachSubscriber ($ callable );
108
108
return ;
109
109
}
@@ -115,13 +115,13 @@ public function attach($callable, $eventKey = null, $options = array()) {
115
115
}
116
116
117
117
/**
118
- * Auxiliary function to attach all implemented callbacks of a CakeEventListener class instance
118
+ * Auxiliary function to attach all implemented callbacks of a Cake\Event\EventListener class instance
119
119
* as individual methods on this manager
120
120
*
121
- * @param CakeEventListener $subscriber
121
+ * @param Cake\Event\EventListener $subscriber
122
122
* @return void
123
123
*/
124
- protected function _attachSubscriber (CakeEventListener $ subscriber ) {
124
+ protected function _attachSubscriber (EventListener $ subscriber ) {
125
125
foreach ($ subscriber ->implementedEvents () as $ eventKey => $ function ) {
126
126
$ options = array ();
127
127
$ method = $ function ;
@@ -143,10 +143,10 @@ protected function _attachSubscriber(CakeEventListener $subscriber) {
143
143
144
144
/**
145
145
* Auxiliary function to extract and return a PHP callback type out of the callable definition
146
- * from the return value of the `implementedEvents` method on a CakeEventListener
146
+ * from the return value of the `implementedEvents` method on a Cake\Event\EventListener
147
147
*
148
148
* @param array $function the array taken from a handler definition for a event
149
- * @param CakeEventListener $object The handler object
149
+ * @param Cake\Event\EventListener $object The handler object
150
150
* @return callback
151
151
*/
152
152
protected function _extractCallable ($ function , $ object ) {
@@ -162,11 +162,11 @@ protected function _extractCallable($function, $object) {
162
162
/**
163
163
* Removes a listener from the active listeners.
164
164
*
165
- * @param callback|CakeEventListener $callable any valid PHP callback type or an instance of CakeEventListener
165
+ * @param callback|Cake\Event\EventListener $callable any valid PHP callback type or an instance of EventListener
166
166
* @return void
167
167
*/
168
168
public function detach ($ callable , $ eventKey = null ) {
169
- if ($ callable instanceof CakeEventListener ) {
169
+ if ($ callable instanceof EventListener ) {
170
170
return $ this ->_detachSubscriber ($ callable , $ eventKey );
171
171
}
172
172
if (empty ($ eventKey )) {
@@ -189,13 +189,13 @@ public function detach($callable, $eventKey = null) {
189
189
}
190
190
191
191
/**
192
- * Auxiliary function to help detach all listeners provided by an object implementing CakeEventListener
192
+ * Auxiliary function to help detach all listeners provided by an object implementing EventListener
193
193
*
194
- * @param CakeEventListener $subscriber the subscriber to be detached
194
+ * @param Cake\Event\EventListener $subscriber the subscriber to be detached
195
195
* @param string $eventKey optional event key name to unsubscribe the listener from
196
196
* @return void
197
197
*/
198
- protected function _detachSubscriber (CakeEventListener $ subscriber , $ eventKey = null ) {
198
+ protected function _detachSubscriber (EventListener $ subscriber , $ eventKey = null ) {
199
199
$ events = $ subscriber ->implementedEvents ();
200
200
if (!empty ($ eventKey ) && empty ($ events [$ eventKey ])) {
201
201
return ;
@@ -220,12 +220,12 @@ protected function _detachSubscriber(CakeEventListener $subscriber, $eventKey =
220
220
/**
221
221
* Dispatches a new event to all configured listeners
222
222
*
223
- * @param string|CakeEvent $event the event key name or instance of CakeEvent
223
+ * @param string|Cake\Event\Event $event the event key name or instance of Event
224
224
* @return void
225
225
*/
226
226
public function dispatch ($ event ) {
227
227
if (is_string ($ event )) {
228
- $ event = new CakeEvent ($ event );
228
+ $ event = new Event ($ event );
229
229
}
230
230
231
231
if (!$ this ->_isGlobal ) {
0 commit comments