Browse Source

Rename EventListener to EventListenerInterface.

ADmad 11 years ago
parent
commit
83168d8edc

+ 2 - 2
src/Controller/Component.php

@@ -15,7 +15,7 @@
 namespace Cake\Controller;
 
 use Cake\Core\InstanceConfigTrait;
-use Cake\Event\EventListener;
+use Cake\Event\EventListenerInterface;
 use Cake\Log\LogTrait;
 
 /**
@@ -56,7 +56,7 @@ use Cake\Log\LogTrait;
  * @link http://book.cakephp.org/3.0/en/controllers/components.html
  * @see Controller::$components
  */
-class Component implements EventListener {
+class Component implements EventListenerInterface {
 
 	use InstanceConfigTrait;
 	use LogTrait;

+ 2 - 2
src/Controller/Controller.php

@@ -17,7 +17,7 @@ namespace Cake\Controller;
 use Cake\Controller\Exception\MissingActionException;
 use Cake\Controller\Exception\PrivateActionException;
 use Cake\Event\Event;
-use Cake\Event\EventListener;
+use Cake\Event\EventListenerInterface;
 use Cake\Event\EventManagerTrait;
 use Cake\Log\LogTrait;
 use Cake\Model\ModelAwareTrait;
@@ -82,7 +82,7 @@ use ReflectionMethod;
  * @property      \Cake\Controller\Component\SessionComponent $Session
  * @link          http://book.cakephp.org/3.0/en/controllers.html
  */
-class Controller implements EventListener {
+class Controller implements EventListenerInterface {
 
 	use EventManagerTrait;
 	use LogTrait;

+ 1 - 1
src/Event/EventListener.php

@@ -19,7 +19,7 @@ namespace Cake\Event;
  * to notify the event manager what methods should be called when an event is triggered.
  *
  */
-interface EventListener {
+interface EventListenerInterface {
 
 /**
  * Returns a list of events this object is implementing. When the class is registered

+ 16 - 16
src/Event/EventManager.php

@@ -76,13 +76,13 @@ class EventManager {
 /**
  * Adds a new listener to an event.
  *
- * @param callback|\Cake\Event\EventListener $callable PHP valid callback type or instance of Cake\Event\EventListener to be called
- * when the event named with $eventKey is triggered. If a Cake\Event\EventListener instance is passed, then the `implementedEvents`
+ * @param callback|\Cake\Event\EventListenerInterface $callable PHP valid callback type or instance of Cake\Event\EventListenerInterface to be called
+ * when the event named with $eventKey is triggered. If a Cake\Event\EventListenerInterface instance is passed, then the `implementedEvents`
  * method will be called on the object to register the declared events individually as methods to be managed by this class.
  * It is possible to define multiple event handlers per event name.
  *
  * @param string $eventKey The event unique identifier name with which the callback will be associated. If $callable
- * is an instance of Cake\Event\EventListener this argument will be ignored
+ * is an instance of Cake\Event\EventListenerInterface this argument will be ignored
  *
  * @param array $options used to set the `priority` flag to the listener. In the future more options may be added.
  * Priorities are treated as queues. Lower values are called before higher ones, and multiple attachments
@@ -90,13 +90,13 @@ class EventManager {
  *
  * @return void
  * @throws \InvalidArgumentException When event key is missing or callable is not an
- *   instance of Cake\Event\EventListener.
+ *   instance of Cake\Event\EventListenerInterface.
  */
 	public function attach($callable, $eventKey = null, array $options = array()) {
-		if (!$eventKey && !($callable instanceof EventListener)) {
+		if (!$eventKey && !($callable instanceof EventListenerInterface)) {
 			throw new \InvalidArgumentException('The eventKey variable is required');
 		}
-		if ($callable instanceof EventListener) {
+		if ($callable instanceof EventListenerInterface) {
 			$this->_attachSubscriber($callable);
 			return;
 		}
@@ -107,13 +107,13 @@ class EventManager {
 	}
 
 /**
- * Auxiliary function to attach all implemented callbacks of a Cake\Event\EventListener class instance
+ * Auxiliary function to attach all implemented callbacks of a Cake\Event\EventListenerInterface class instance
  * as individual methods on this manager
  *
- * @param \Cake\Event\EventListener $subscriber Event listener.
+ * @param \Cake\Event\EventListenerInterface $subscriber Event listener.
  * @return void
  */
-	protected function _attachSubscriber(EventListener $subscriber) {
+	protected function _attachSubscriber(EventListenerInterface $subscriber) {
 		foreach ((array)$subscriber->implementedEvents() as $eventKey => $function) {
 			$options = array();
 			$method = $function;
@@ -135,10 +135,10 @@ class EventManager {
 
 /**
  * Auxiliary function to extract and return a PHP callback type out of the callable definition
- * from the return value of the `implementedEvents` method on a Cake\Event\EventListener
+ * from the return value of the `implementedEvents` method on a Cake\Event\EventListenerInterface
  *
  * @param array $function the array taken from a handler definition for an event
- * @param \Cake\Event\EventListener $object The handler object
+ * @param \Cake\Event\EventListenerInterface $object The handler object
  * @return callback
  */
 	protected function _extractCallable($function, $object) {
@@ -154,12 +154,12 @@ class EventManager {
 /**
  * Removes a listener from the active listeners.
  *
- * @param callback|\Cake\Event\EventListener $callable any valid PHP callback type or an instance of EventListener
+ * @param callback|\Cake\Event\EventListenerInterface $callable any valid PHP callback type or an instance of EventListenerInterface
  * @param string $eventKey The event unique identifier name with which the callback has been associated
  * @return void
  */
 	public function detach($callable, $eventKey = null) {
-		if ($callable instanceof EventListener) {
+		if ($callable instanceof EventListenerInterface) {
 			return $this->_detachSubscriber($callable, $eventKey);
 		}
 		if (empty($eventKey)) {
@@ -182,13 +182,13 @@ class EventManager {
 	}
 
 /**
- * Auxiliary function to help detach all listeners provided by an object implementing EventListener
+ * Auxiliary function to help detach all listeners provided by an object implementing EventListenerInterface
  *
- * @param \Cake\Event\EventListener $subscriber the subscriber to be detached
+ * @param \Cake\Event\EventListenerInterface $subscriber the subscriber to be detached
  * @param string $eventKey optional event key name to unsubscribe the listener from
  * @return void
  */
-	protected function _detachSubscriber(EventListener $subscriber, $eventKey = null) {
+	protected function _detachSubscriber(EventListenerInterface $subscriber, $eventKey = null) {
 		$events = (array)$subscriber->implementedEvents();
 		if (!empty($eventKey) && empty($events[$eventKey])) {
 			return;

+ 2 - 2
src/ORM/Behavior.php

@@ -16,7 +16,7 @@ namespace Cake\ORM;
 
 use Cake\Core\Exception\Exception;
 use Cake\Core\InstanceConfigTrait;
-use Cake\Event\EventListener;
+use Cake\Event\EventListenerInterface;
 
 /**
  * Base class for behaviors.
@@ -99,7 +99,7 @@ use Cake\Event\EventListener;
  * @see \Cake\ORM\Table::addBehavior()
  * @see \Cake\Event\EventManager
  */
-class Behavior implements EventListener {
+class Behavior implements EventListenerInterface {
 
 	use InstanceConfigTrait;
 

+ 2 - 2
src/ORM/Table.php

@@ -20,7 +20,7 @@ use Cake\Database\Schema\Table as Schema;
 use Cake\Database\Type;
 use Cake\Datasource\EntityInterface;
 use Cake\Datasource\RepositoryInterface;
-use Cake\Event\EventListener;
+use Cake\Event\EventListenerInterface;
 use Cake\Event\EventManager;
 use Cake\Event\EventManagerTrait;
 use Cake\ORM\AssociationCollection;
@@ -105,7 +105,7 @@ use RuntimeException;
  *
  * @see \Cake\Event\EventManager for reference on the events system.
  */
-class Table implements RepositoryInterface, EventListener {
+class Table implements RepositoryInterface, EventListenerInterface {
 
 	use EventManagerTrait;
 

+ 4 - 4
src/Routing/Dispatcher.php

@@ -15,7 +15,7 @@
 namespace Cake\Routing;
 
 use Cake\Controller\Controller;
-use Cake\Event\EventListener;
+use Cake\Event\EventListenerInterface;
 use Cake\Event\EventManagerTrait;
 use Cake\Network\Request;
 use Cake\Network\Response;
@@ -133,11 +133,11 @@ class Dispatcher {
  * The added filter will be attached to the event manager used
  * by this dispatcher.
  *
- * @param \Cake\Event\EventListener $filter The filter to connect. Can be
- *   any EventListener. Typically an instance of \Cake\Routing\DispatcherFilter.
+ * @param \Cake\Event\EventListenerInterface $filter The filter to connect. Can be
+ *   any EventListenerInterface. Typically an instance of \Cake\Routing\DispatcherFilter.
  * @return void
  */
-	public function addFilter(EventListener $filter) {
+	public function addFilter(EventListenerInterface $filter) {
 		$this->_filters[] = $filter;
 		$this->eventManager()->attach($filter);
 	}

+ 2 - 2
src/Routing/DispatcherFilter.php

@@ -16,7 +16,7 @@ namespace Cake\Routing;
 
 use Cake\Core\InstanceConfigTrait;
 use Cake\Event\Event;
-use Cake\Event\EventListener;
+use Cake\Event\EventListenerInterface;
 use InvalidArgumentException;
 
 /**
@@ -64,7 +64,7 @@ use InvalidArgumentException;
  * callback as the conditions could change during the dispatch cycle.
  *
  */
-class DispatcherFilter implements EventListener {
+class DispatcherFilter implements EventListenerInterface {
 
 	use InstanceConfigTrait;
 

+ 2 - 2
src/View/Helper.php

@@ -15,7 +15,7 @@
 namespace Cake\View;
 
 use Cake\Core\InstanceConfigTrait;
-use Cake\Event\EventListener;
+use Cake\Event\EventListenerInterface;
 
 /**
  * Abstract base class for all other Helpers in CakePHP.
@@ -39,7 +39,7 @@ use Cake\Event\EventListener;
  *   If a listener returns a non-null value, the output of the rendered file will be set to that.
  *
  */
-class Helper implements EventListener {
+class Helper implements EventListenerInterface {
 
 	use InstanceConfigTrait;
 

+ 8 - 8
tests/TestCase/Event/EventManagerTest.php

@@ -15,7 +15,7 @@
 namespace Cake\Test\TestCase\Event;
 
 use Cake\Event\Event;
-use Cake\Event\EventListener;
+use Cake\Event\EventListenerInterface;
 use Cake\Event\EventManager;
 use Cake\TestSuite\TestCase;
 
@@ -59,7 +59,7 @@ class EventTestListener {
 /**
  * Mock used for testing the subscriber objects
  */
-class CustomTestEventListener extends EventTestListener implements EventListener {
+class CustomTestEventListenerInterface extends EventTestListener implements EventListenerInterface {
 
 	public function implementedEvents() {
 		return array(
@@ -298,7 +298,7 @@ class EventManagerTest extends TestCase {
  */
 	public function testAttachSubscriber() {
 		$manager = new EventManager();
-		$listener = $this->getMock(__NAMESPACE__ . '\CustomTestEventListener', array('secondListenerFunction'));
+		$listener = $this->getMock(__NAMESPACE__ . '\CustomTestEventListenerInterface', array('secondListenerFunction'));
 		$manager->attach($listener);
 
 		$event = new Event('fake.event');
@@ -321,7 +321,7 @@ class EventManagerTest extends TestCase {
  */
 	public function testAttachSubscriberMultiple() {
 		$manager = new EventManager();
-		$listener = $this->getMock(__NAMESPACE__ . '\CustomTestEventListener', array('listenerFunction', 'thirdListenerFunction'));
+		$listener = $this->getMock(__NAMESPACE__ . '\CustomTestEventListenerInterface', array('listenerFunction', 'thirdListenerFunction'));
 		$manager->attach($listener);
 		$event = new Event('multiple.handlers');
 		$listener->expects($this->once())
@@ -340,7 +340,7 @@ class EventManagerTest extends TestCase {
  */
 	public function testDetachSubscriber() {
 		$manager = new EventManager();
-		$listener = $this->getMock(__NAMESPACE__ . '\CustomTestEventListener', array('secondListenerFunction'));
+		$listener = $this->getMock(__NAMESPACE__ . '\CustomTestEventListenerInterface', array('secondListenerFunction'));
 		$manager->attach($listener);
 		$expected = array(
 			array('callable' => array($listener, 'secondListenerFunction'))
@@ -419,7 +419,7 @@ class EventManagerTest extends TestCase {
 	public function testDispatchPrioritizedWithGlobal() {
 		$generalManager = $this->getMock('Cake\Event\EventManager');
 		$manager = new EventManager();
-		$listener = new CustomTestEventListener();
+		$listener = new CustomTestEventListenerInterface();
 		$event = new Event('fake.event');
 
 		EventManager::instance($generalManager);
@@ -450,7 +450,7 @@ class EventManagerTest extends TestCase {
 	public function testDispatchGlobalBeforeLocal() {
 		$generalManager = $this->getMock('Cake\Event\EventManager');
 		$manager = new EventManager();
-		$listener = new CustomTestEventListener();
+		$listener = new CustomTestEventListenerInterface();
 		$event = new Event('fake.event');
 
 		EventManager::instance($generalManager);
@@ -499,7 +499,7 @@ class EventManagerTest extends TestCase {
  * @return void
  */
 	public function testDispatchWithGlobalAndLocalEvents() {
-		$listener = new CustomTestEventListener();
+		$listener = new CustomTestEventListenerInterface();
 		EventManager::instance()->attach($listener);
 		$listener2 = new EventTestListener();
 		$manager = new EventManager();

+ 4 - 4
tests/TestCase/View/ViewTest.php

@@ -20,7 +20,7 @@ use Cake\Core\App;
 use Cake\Core\Configure;
 use Cake\Core\Plugin;
 use Cake\Event\Event;
-use Cake\Event\EventListener;
+use Cake\Event\EventListenerInterface;
 use Cake\Network\Request;
 use Cake\Routing\Router;
 use Cake\TestSuite\TestCase;
@@ -210,11 +210,11 @@ class TestObjectWithoutToString {
 }
 
 /**
- * Class TestViewEventListener
+ * Class TestViewEventListenerInterface
  *
  * An event listener to test cakePHP events
  */
-class TestViewEventListener implements EventListener {
+class TestViewEventListenerInterface implements EventListenerInterface {
 
 /**
  * type of view before rendering has occurred
@@ -894,7 +894,7 @@ class ViewTest extends TestCase {
 	public function testViewEvent() {
 		$View = $this->PostsController->createView();
 		$View->autoLayout = false;
-		$listener = new TestViewEventListener();
+		$listener = new TestViewEventListenerInterface();
 
 		$View->eventManager()->attach($listener);