Skip to content

Commit

Permalink
Rename EventListener to EventListenerInterface.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Oct 16, 2014
1 parent e6deb49 commit 83168d8
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Component.php
Expand Up @@ -15,7 +15,7 @@
namespace Cake\Controller;

use Cake\Core\InstanceConfigTrait;
use Cake\Event\EventListener;
use Cake\Event\EventListenerInterface;
use Cake\Log\LogTrait;

/**
Expand Down Expand Up @@ -56,7 +56,7 @@
* @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;
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Controller.php
Expand Up @@ -17,7 +17,7 @@
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;
Expand Down Expand Up @@ -82,7 +82,7 @@
* @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;
Expand Down
Expand Up @@ -19,7 +19,7 @@
* 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
Expand Down
32 changes: 16 additions & 16 deletions src/Event/EventManager.php
Expand Up @@ -76,27 +76,27 @@ public static function instance($manager = null) {
/**
* 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
* added to the same priority queue will be treated in the order of insertion.
*
* @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;
}
Expand All @@ -107,13 +107,13 @@ public function attach($callable, $eventKey = null, array $options = array()) {
}

/**
* 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;
Expand All @@ -135,10 +135,10 @@ protected function _attachSubscriber(EventListener $subscriber) {

/**
* 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) {
Expand All @@ -154,12 +154,12 @@ protected function _extractCallable($function, $object) {
/**
* 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)) {
Expand All @@ -182,13 +182,13 @@ public function detach($callable, $eventKey = null) {
}

/**
* 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;
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Behavior.php
Expand Up @@ -16,7 +16,7 @@

use Cake\Core\Exception\Exception;
use Cake\Core\InstanceConfigTrait;
use Cake\Event\EventListener;
use Cake\Event\EventListenerInterface;

/**
* Base class for behaviors.
Expand Down Expand Up @@ -99,7 +99,7 @@
* @see \Cake\ORM\Table::addBehavior()
* @see \Cake\Event\EventManager
*/
class Behavior implements EventListener {
class Behavior implements EventListenerInterface {

use InstanceConfigTrait;

Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Table.php
Expand Up @@ -20,7 +20,7 @@
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;
Expand Down Expand Up @@ -105,7 +105,7 @@
*
* @see \Cake\Event\EventManager for reference on the events system.
*/
class Table implements RepositoryInterface, EventListener {
class Table implements RepositoryInterface, EventListenerInterface {

use EventManagerTrait;

Expand Down
8 changes: 4 additions & 4 deletions src/Routing/Dispatcher.php
Expand Up @@ -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;
Expand Down Expand Up @@ -133,11 +133,11 @@ protected function _invoke(Controller $controller) {
* 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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Routing/DispatcherFilter.php
Expand Up @@ -16,7 +16,7 @@

use Cake\Core\InstanceConfigTrait;
use Cake\Event\Event;
use Cake\Event\EventListener;
use Cake\Event\EventListenerInterface;
use InvalidArgumentException;

/**
Expand Down Expand Up @@ -64,7 +64,7 @@
* callback as the conditions could change during the dispatch cycle.
*
*/
class DispatcherFilter implements EventListener {
class DispatcherFilter implements EventListenerInterface {

use InstanceConfigTrait;

Expand Down
4 changes: 2 additions & 2 deletions src/View/Helper.php
Expand Up @@ -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.
Expand All @@ -39,7 +39,7 @@
* 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;

Expand Down
16 changes: 8 additions & 8 deletions tests/TestCase/Event/EventManagerTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -59,7 +59,7 @@ public function stopListener($event) {
/**
* Mock used for testing the subscriber objects
*/
class CustomTestEventListener extends EventTestListener implements EventListener {
class CustomTestEventListenerInterface extends EventTestListener implements EventListenerInterface {

public function implementedEvents() {
return array(
Expand Down Expand Up @@ -298,7 +298,7 @@ public function testDispatchPrioritized() {
*/
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');
Expand All @@ -321,7 +321,7 @@ public function testAttachSubscriber() {
*/
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())
Expand All @@ -340,7 +340,7 @@ public function testAttachSubscriberMultiple() {
*/
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'))
Expand Down Expand Up @@ -419,7 +419,7 @@ public function testStopPropagation() {
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);
Expand Down Expand Up @@ -450,7 +450,7 @@ public function testDispatchPrioritizedWithGlobal() {
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);
Expand Down Expand Up @@ -499,7 +499,7 @@ public function testDispatchLocalHandledByGlobal() {
* @return void
*/
public function testDispatchWithGlobalAndLocalEvents() {
$listener = new CustomTestEventListener();
$listener = new CustomTestEventListenerInterface();
EventManager::instance()->attach($listener);
$listener2 = new EventTestListener();
$manager = new EventManager();
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/View/ViewTest.php
Expand Up @@ -20,7 +20,7 @@
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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -894,7 +894,7 @@ public function testElementCache() {
public function testViewEvent() {
$View = $this->PostsController->createView();
$View->autoLayout = false;
$listener = new TestViewEventListener();
$listener = new TestViewEventListenerInterface();

$View->eventManager()->attach($listener);

Expand Down

0 comments on commit 83168d8

Please sign in to comment.