Skip to content

Commit acb44bf

Browse files
committed
Updated Event folder
1 parent 89c3e98 commit acb44bf

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

lib/Cake/Event/CakeEvent.php renamed to lib/Cake/Event/Event.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* @since CakePHP(tm) v 2.1
1616
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1717
*/
18+
namespace Cake\Event;
1819

1920
/**
2021
* Represent the transport class of events across the system, it receives a name, and subject and an optional
@@ -23,7 +24,7 @@
2324
*
2425
* @package Cake.Event
2526
*/
26-
class CakeEvent {
27+
class Event {
2728

2829
/**
2930
* Name of the event
@@ -70,8 +71,8 @@ class CakeEvent {
7071
* ## Examples of usage:
7172
*
7273
* {{{
73-
* $event = new CakeEvent('Order.afterBuy', $this, array('buyer' => $userData));
74-
* $event = new CakeEvent('User.afterRegister', $UserModel);
74+
* $event = new Event('Order.afterBuy', $this, array('buyer' => $userData));
75+
* $event = new Event('User.afterRegister', $UserModel);
7576
* }}}
7677
*
7778
*/

lib/Cake/Event/CakeEventListener.php renamed to lib/Cake/Event/EventListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
* @since CakePHP(tm) v 2.1
1616
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1717
*/
18+
namespace Cake\Event;
1819

1920
/**
2021
* Objects implementing this interface should declare the `implementedEvents` function
2122
* to hint the event manager what methods should be called when an event is triggered.
2223
*
2324
* @package Cake.Event
2425
*/
25-
interface CakeEventListener {
26+
interface EventListener {
2627

2728
/**
2829
* Returns a list of events this object is implementing, when the class is registered

lib/Cake/Event/CakeEventManager.php renamed to lib/Cake/Event/EventManager.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
* @since CakePHP(tm) v 2.1
1616
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1717
*/
18-
19-
App::uses('CakeEventListener', 'Event');
18+
namespace Cake\Event;
19+
use Cake\Error;
2020

2121
/**
2222
* The event manager is responsible for keeping track of event listeners and pass the correct
@@ -26,7 +26,7 @@
2626
*
2727
* @package Cake.Event
2828
*/
29-
class CakeEventManager {
29+
class EventManager {
3030

3131
/**
3232
* The default priority queue value for new attached listeners
@@ -38,7 +38,7 @@ class CakeEventManager {
3838
/**
3939
* The globally available instance, used for dispatching events attached from any scope
4040
*
41-
* @var CakeEventManager
41+
* @var Cake\Event\EventManager
4242
*/
4343
protected static $_generalManager = null;
4444

@@ -57,22 +57,22 @@ class CakeEventManager {
5757
protected $_isGlobal = false;
5858

5959
/**
60-
* Returns the globally available instance of a CakeEventManager
60+
* Returns the globally available instance of a Cake\Event\EventManager
6161
* this is used for dispatching events attached from outside the scope
6262
* other managers were created. Usually for creating hook systems or inter-class
6363
* communication
6464
*
6565
* If called with a first params, it will be set as the globally available instance
6666
*
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
6969
*/
7070
public static function instance($manager = null) {
71-
if ($manager instanceof CakeEventManager) {
71+
if ($manager instanceof EventManager) {
7272
self::$_generalManager = $manager;
7373
}
7474
if (empty(self::$_generalManager)) {
75-
self::$_generalManager = new CakeEventManager;
75+
self::$_generalManager = new EventManager;
7676
}
7777

7878
self::$_generalManager->_isGlobal = true;
@@ -82,28 +82,28 @@ public static function instance($manager = null) {
8282
/**
8383
* Adds a new listener to an event. Listeners
8484
*
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`
8787
* method will be called on the object to register the declared events individually as methods to be managed by this class.
8888
* It is possible to define multiple event handlers per event name.
8989
*
9090
* @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
9292
*
9393
* @param array $options used to set the `priority` and `passParams` flags to the listener.
9494
* Priorities are handled like queues, and multiple attachments into the same priority queue will be treated in
9595
* 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
9797
*
9898
* @return void
9999
* @throws InvalidArgumentException When event key is missing or callable is not an
100-
* instance of CakeEventListener.
100+
* instance of Cake\Event\EventListener.
101101
*/
102102
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'));
105105
}
106-
if ($callable instanceof CakeEventListener) {
106+
if ($callable instanceof EventListener) {
107107
$this->_attachSubscriber($callable);
108108
return;
109109
}
@@ -115,13 +115,13 @@ public function attach($callable, $eventKey = null, $options = array()) {
115115
}
116116

117117
/**
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
119119
* as individual methods on this manager
120120
*
121-
* @param CakeEventListener $subscriber
121+
* @param Cake\Event\EventListener $subscriber
122122
* @return void
123123
*/
124-
protected function _attachSubscriber(CakeEventListener $subscriber) {
124+
protected function _attachSubscriber(EventListener $subscriber) {
125125
foreach ($subscriber->implementedEvents() as $eventKey => $function) {
126126
$options = array();
127127
$method = $function;
@@ -143,10 +143,10 @@ protected function _attachSubscriber(CakeEventListener $subscriber) {
143143

144144
/**
145145
* 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
147147
*
148148
* @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
150150
* @return callback
151151
*/
152152
protected function _extractCallable($function, $object) {
@@ -162,11 +162,11 @@ protected function _extractCallable($function, $object) {
162162
/**
163163
* Removes a listener from the active listeners.
164164
*
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
166166
* @return void
167167
*/
168168
public function detach($callable, $eventKey = null) {
169-
if ($callable instanceof CakeEventListener) {
169+
if ($callable instanceof EventListener) {
170170
return $this->_detachSubscriber($callable, $eventKey);
171171
}
172172
if (empty($eventKey)) {
@@ -189,13 +189,13 @@ public function detach($callable, $eventKey = null) {
189189
}
190190

191191
/**
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
193193
*
194-
* @param CakeEventListener $subscriber the subscriber to be detached
194+
* @param Cake\Event\EventListener $subscriber the subscriber to be detached
195195
* @param string $eventKey optional event key name to unsubscribe the listener from
196196
* @return void
197197
*/
198-
protected function _detachSubscriber(CakeEventListener $subscriber, $eventKey = null) {
198+
protected function _detachSubscriber(EventListener $subscriber, $eventKey = null) {
199199
$events = $subscriber->implementedEvents();
200200
if (!empty($eventKey) && empty($events[$eventKey])) {
201201
return;
@@ -220,12 +220,12 @@ protected function _detachSubscriber(CakeEventListener $subscriber, $eventKey =
220220
/**
221221
* Dispatches a new event to all configured listeners
222222
*
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
224224
* @return void
225225
*/
226226
public function dispatch($event) {
227227
if (is_string($event)) {
228-
$event = new CakeEvent($event);
228+
$event = new Event($event);
229229
}
230230

231231
if (!$this->_isGlobal) {

0 commit comments

Comments
 (0)