diff --git a/src/FuzeWorks/Events.php b/src/FuzeWorks/Events.php index 8877994..492c396 100644 --- a/src/FuzeWorks/Events.php +++ b/src/FuzeWorks/Events.php @@ -47,7 +47,7 @@ use FuzeWorks\Exception\EventException; * If we want to add the current time at the end of each page title, we need to hook to the corresponding event. Those events are found in the 'events' directory in the system directory. * The event that will be fired when the title is changing is called layoutSetTitleEvent. So if we want our module to hook to that event, we add the following to the constructor: * - * Events::addListener(array($this, "onLayoutSetTitleEvent"), "layoutSetTitleEvent", EventPriority::NORMAL); + * Events::addListener(array($this, "onLayoutSetTitleEvent"), "layoutSetTitleEvent", Priority::NORMAL); * * This will add the function "onLayoutSetTitleEvent" of our current class ($this) to the list of listeners with priority NORMAL. So we need to add * a method called onLayoutSetTitleEvent($event) it is very important to add the pointer-reference (&) or return the event, otherwise it doesn't change the event variables. @@ -80,17 +80,17 @@ class Events * * @param callable $callback The callback when the events get fired, see {@link http://php.net/manual/en/language.types.callable.php PHP.net} * @param string $eventName The name of the event - * @param int $priority The priority, even though integers are valid, please use EventPriority (for example EventPriority::Lowest) + * @param int $priority The priority, even though integers are valid, please use Priority (for example Priority::Lowest) * @param mixed $parameters,... Parameters for the listener * - * @see EventPriority + * @see Priority * * @throws EventException */ - public static function addListener(callable $callback, string $eventName, int $priority = EventPriority::NORMAL) + public static function addListener(callable $callback, string $eventName, int $priority = Priority::NORMAL) { // Perform multiple checks - if (EventPriority::getPriority($priority) == false) { + if (Priority::getPriority($priority) == false) { throw new EventException('Can not add listener: Unknown priority '.$priority, 1); } @@ -123,15 +123,15 @@ class Events * * @param mixed callback The callback when the events get fired, see {@link http://php.net/manual/en/language.types.callable.php PHP.net} * @param string $eventName The name of the event - * @param int $priority The priority, even though integers are valid, please use EventPriority (for example EventPriority::Lowest) + * @param int $priority The priority, even though integers are valid, please use Priority (for example Priority::Lowest) * - * @see EventPriority + * @see Priority * * @throws EventException */ - public static function removeListener(callable $callback, string $eventName, $priority = EventPriority::NORMAL) + public static function removeListener(callable $callback, string $eventName, $priority = Priority::NORMAL) { - if (EventPriority::getPriority($priority) == false) { + if (Priority::getPriority($priority) == false) { throw new EventException('Unknown priority '.$priority); } @@ -220,11 +220,11 @@ class Events Logger::newLevel("Firing Event: '".$eventName."'. Found listeners: "); //Loop from the highest priority to the lowest - for ($priority = EventPriority::getHighestPriority(); $priority <= EventPriority::getLowestPriority(); ++$priority) { + for ($priority = Priority::getHighestPriority(); $priority <= Priority::getLowestPriority(); ++$priority) { //Check for listeners in this priority if (isset(self::$listeners[$eventName][$priority])) { $listeners = self::$listeners[$eventName][$priority]; - Logger::newLevel('Found listeners with priority '.EventPriority::getPriority($priority)); + Logger::newLevel('Found listeners with priority '.Priority::getPriority($priority)); //Fire the event to each listener foreach ($listeners as $callbackArray) { // @codeCoverageIgnoreStart diff --git a/src/FuzeWorks/EventPriority.php b/src/FuzeWorks/Priority.php similarity index 77% rename from src/FuzeWorks/EventPriority.php rename to src/FuzeWorks/Priority.php index d4078f6..26a0610 100644 --- a/src/FuzeWorks/EventPriority.php +++ b/src/FuzeWorks/Priority.php @@ -37,22 +37,22 @@ namespace FuzeWorks; /** - * Class EventPriority. + * Class Priority. * - * The EventPriority is an "enum" which gives priorities an integer value, the higher the integer value, the lower the + * The Priority is an "enum" which gives priorities an integer value, the higher the integer value, the lower the * priority. The available priorities are, from highest to lowest: * - * EventPriority::MONITOR - * EventPriority::HIGHEST - * EventPriority::HIGH - * EventPriority::NORMAL - * EventPriority::LOW - * EventPriority::LOWEST + * Priority::MONITOR + * Priority::HIGHEST + * Priority::HIGH + * Priority::NORMAL + * Priority::LOW + * Priority::LOWEST * * @author TechFuze * @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net) */ -abstract class EventPriority +abstract class Priority { const LOWEST = 5; const LOW = 4; @@ -72,17 +72,17 @@ abstract class EventPriority { switch ($intPriorty) { case 5: - return 'EventPriority::LOWEST'; + return 'Priority::LOWEST'; case 4: - return 'EventPriority::LOW'; + return 'Priority::LOW'; case 3: - return 'EventPriority::NORMAL'; + return 'Priority::NORMAL'; case 2: - return 'EventPriority::HIGH'; + return 'Priority::HIGH'; case 1: - return 'EventPriority::HIGHEST'; + return 'Priority::HIGHEST'; case 0: - return 'EventPriority::MONITOR'; + return 'Priority::MONITOR'; default: return false; } @@ -90,7 +90,7 @@ abstract class EventPriority /** * Returns the highest priority - * This function is needed for the firing of events in the right order,. + * This function is needed for executing in the right order,. * * @return int */ @@ -101,7 +101,7 @@ abstract class EventPriority /** * Returns the lowest priority - * This function is needed for the firing of events in the right order,. + * This function is needed for executing in the right order,. * * @return int */ diff --git a/test/core/core_configTest.php b/test/core/core_configTest.php index ee2954b..64ee276 100644 --- a/test/core/core_configTest.php +++ b/test/core/core_configTest.php @@ -36,7 +36,7 @@ use FuzeWorks\Config; use FuzeWorks\Event\ConfigGetEvent; -use FuzeWorks\EventPriority; +use FuzeWorks\Priority; use FuzeWorks\Events; /** @@ -87,7 +87,7 @@ class configTest extends CoreTestAbstract // Register listener Events::addListener(function($event){ $event->setCancelled(true); - }, 'configGetEvent', EventPriority::NORMAL); + }, 'configGetEvent', Priority::NORMAL); // Attempt and load a config file $config = $this->config->getConfig('loadConfigCancel'); @@ -104,7 +104,7 @@ class configTest extends CoreTestAbstract Events::addListener(function($event){ /** @var ConfigGetEvent $event */ $event->configName = 'TestLoadConfigIntercept'; - }, 'configGetEvent', EventPriority::NORMAL); + }, 'configGetEvent', Priority::NORMAL); // Load file $config = $this->config->getConfig('does_not_exist', ['test'.DS.'config'.DS.'TestLoadConfigIntercept']); diff --git a/test/core/core_eventTest.php b/test/core/core_eventTest.php index 8d6cb16..fad77cf 100644 --- a/test/core/core_eventTest.php +++ b/test/core/core_eventTest.php @@ -35,7 +35,7 @@ */ use FuzeWorks\Events; use FuzeWorks\Event; -use FuzeWorks\EventPriority; +use FuzeWorks\Priority; /** * Class EventTest. @@ -54,7 +54,7 @@ class eventTest extends CoreTestAbstract public function testCancelEvent() { - Events::addListener(array($this, 'listener_cancel'), 'testCancelEvent', EventPriority::NORMAL); + Events::addListener(array($this, 'listener_cancel'), 'testCancelEvent', Priority::NORMAL); $event = Events::fireEvent('testCancelEvent'); $this->assertTrue($event->isCancelled()); @@ -62,8 +62,8 @@ class eventTest extends CoreTestAbstract public function testUncancelEvent() { - Events::addListener(array($this, 'listener_cancel'), 'testUncancelEvent', EventPriority::HIGH); - Events::addListener(array($this, 'listener_uncancel'), 'testUncancelEvent', EventPriority::LOW); + Events::addListener(array($this, 'listener_cancel'), 'testUncancelEvent', Priority::HIGH); + Events::addListener(array($this, 'listener_uncancel'), 'testUncancelEvent', Priority::LOW); $event = Events::fireEvent('testUncancelEvent'); $this->assertFalse($event->isCancelled()); diff --git a/test/core/core_eventsTest.php b/test/core/core_eventsTest.php index 14ab509..ef5ff7b 100644 --- a/test/core/core_eventsTest.php +++ b/test/core/core_eventsTest.php @@ -36,7 +36,7 @@ use FuzeWorks\Event; use FuzeWorks\Events; -use FuzeWorks\EventPriority; +use FuzeWorks\Priority; /** * Class EventTest. @@ -50,7 +50,7 @@ class eventsTest extends CoreTestAbstract $mock = $this->getMockBuilder(Observer::class)->setMethods(['mockMethod'])->getMock(); $mock->expects($this->once())->method('mockMethod'); - Events::addListener(array($mock, 'mockMethod'), 'mockEvent', EventPriority::NORMAL); + Events::addListener(array($mock, 'mockMethod'), 'mockEvent', Priority::NORMAL); Events::fireEvent('mockEvent'); } @@ -64,7 +64,7 @@ class eventsTest extends CoreTestAbstract $listener = $this->getMockBuilder(Observer::class)->setMethods(['mockListener'])->getMock(); $listener->expects($this->once())->method('mockListener')->with($this->equalTo($event)); - Events::addListener(array($listener, 'mockListener'), get_class($event), EventPriority::NORMAL); + Events::addListener(array($listener, 'mockListener'), get_class($event), Priority::NORMAL); Events::fireEvent($event); } @@ -81,7 +81,7 @@ class eventsTest extends CoreTestAbstract Events::addListener(function($event) { $this->assertEquals('value', $event->key); - }, $eventName, EventPriority::NORMAL); + }, $eventName, Priority::NORMAL); Events::fireEvent($event); } @@ -116,7 +116,7 @@ class eventsTest extends CoreTestAbstract $event->key = 2; return $event; - }, $eventName, EventPriority::HIGH); + }, $eventName, Priority::HIGH); // The second listener, should be called second due to LOW priority Events::addListener(function($event) { @@ -124,7 +124,7 @@ class eventsTest extends CoreTestAbstract $event->key = 3; return $event; - }, $eventName, EventPriority::LOW); + }, $eventName, Priority::LOW); // Fire the event and test if the key is the result of the last listener Events::fireEvent($event); @@ -157,10 +157,10 @@ class eventsTest extends CoreTestAbstract // First add the listener, expect it to be never called $listener = $this->getMockBuilder(Observer::class)->setMethods(['mockListener'])->getMock(); $listener->expects($this->never())->method('mockListener'); - Events::addListener(array($listener, 'mockListener'), 'mockEvent', EventPriority::NORMAL); + Events::addListener(array($listener, 'mockListener'), 'mockEvent', Priority::NORMAL); // Now try and remove it - Events::removeListener(array($listener, 'mockListener'), 'mockEvent', EventPriority::NORMAL); + Events::removeListener(array($listener, 'mockListener'), 'mockEvent', Priority::NORMAL); // And now fire the event Events::fireEvent('mockEvent'); @@ -181,7 +181,7 @@ class eventsTest extends CoreTestAbstract */ public function testAddInvalidNameListener() { - Events::addListener(function($e) {}, '', EventPriority::NORMAL); + Events::addListener(function($e) {}, '', Priority::NORMAL); } /** @@ -198,7 +198,7 @@ class eventsTest extends CoreTestAbstract */ public function testRemoveUnsetEventListener() { - $this->assertNull(Events::removeListener(function($event){}, 'emptyListenerArray', EventPriority::NORMAL)); + $this->assertNull(Events::removeListener(function($event){}, 'emptyListenerArray', Priority::NORMAL)); } /** @@ -206,8 +206,8 @@ class eventsTest extends CoreTestAbstract */ public function testRemoveUnsetListener() { - Events::addListener(function($e) {}, 'mockEvent', EventPriority::NORMAL); - $this->assertNull(Events::removeListener(function($x) {echo "Called"; }, 'mockEvent', EventPriority::NORMAL)); + Events::addListener(function($e) {}, 'mockEvent', Priority::NORMAL); + $this->assertNull(Events::removeListener(function($x) {echo "Called"; }, 'mockEvent', Priority::NORMAL)); } /** @@ -223,7 +223,7 @@ class eventsTest extends CoreTestAbstract Events::addListener(function($event, $passVariable) { $this->assertEquals('value', $passVariable); - }, $eventName, EventPriority::NORMAL, $passVariable); + }, $eventName, Priority::NORMAL, $passVariable); Events::fireEvent($event); } @@ -233,7 +233,7 @@ class eventsTest extends CoreTestAbstract // First add the listener, expect it to be never called $listener = $this->getMockBuilder(Observer::class)->setMethods(['mockListener'])->getMock(); $listener->expects($this->never())->method('mockListener'); - Events::addListener(array($listener, 'mockListener'), 'mockEvent', EventPriority::NORMAL); + Events::addListener(array($listener, 'mockListener'), 'mockEvent', Priority::NORMAL); // Disable the event syste, Events::disable(); @@ -247,7 +247,7 @@ class eventsTest extends CoreTestAbstract // First add the listener, expect it to be never called $listener = $this->getMockBuilder(Observer::class)->setMethods(['mockListener'])->getMock(); $listener->expects($this->once())->method('mockListener'); - Events::addListener(array($listener, 'mockListener'), 'mockEvent', EventPriority::NORMAL); + Events::addListener(array($listener, 'mockListener'), 'mockEvent', Priority::NORMAL); // Disable the event syste, Events::disable(); diff --git a/test/core/core_helperTest.php b/test/core/core_helperTest.php index 79bc81b..bc5d625 100644 --- a/test/core/core_helperTest.php +++ b/test/core/core_helperTest.php @@ -34,7 +34,7 @@ * @version Version 1.2.0 */ -use FuzeWorks\EventPriority; +use FuzeWorks\Priority; use FuzeWorks\Events; use FuzeWorks\Helpers; @@ -129,7 +129,7 @@ class helperTest extends CoreTestAbstract Events::addListener(function($event) { $event->setCancelled(true); - }, 'helperLoadEvent', EventPriority::NORMAL); + }, 'helperLoadEvent', Priority::NORMAL); $this->assertFalse($this->helpers->load('TestCancelLoadHelper')); } diff --git a/test/core/core_eventPriorityTest.php b/test/core/core_priorityTest.php similarity index 58% rename from test/core/core_eventPriorityTest.php rename to test/core/core_priorityTest.php index 08b4f88..4b198d1 100644 --- a/test/core/core_eventPriorityTest.php +++ b/test/core/core_priorityTest.php @@ -33,49 +33,49 @@ * * @version Version 1.2.0 */ -use FuzeWorks\EventPriority; +use FuzeWorks\Priority; /** - * Class EventPriorityTest. + * Class priorityTest. * - * This test will test the EventPriority class + * This test will test the Priority class */ -class eventPriorityTest extends CoreTestAbstract +class priorityTest extends CoreTestAbstract { public function testPriorities() { - $this->assertEquals(EventPriority::LOWEST, 5); - $this->assertEquals(EventPriority::LOW, 4); - $this->assertEquals(EventPriority::NORMAL, 3); - $this->assertEquals(EventPriority::HIGH, 2); - $this->assertEquals(EventPriority::HIGHEST, 1); - $this->assertEquals(EventPriority::MONITOR, 0); + $this->assertEquals(Priority::LOWEST, 5); + $this->assertEquals(Priority::LOW, 4); + $this->assertEquals(Priority::NORMAL, 3); + $this->assertEquals(Priority::HIGH, 2); + $this->assertEquals(Priority::HIGHEST, 1); + $this->assertEquals(Priority::MONITOR, 0); } public function testGetPriority() { - $this->assertEquals(EventPriority::getPriority(5), 'EventPriority::LOWEST'); - $this->assertEquals(EventPriority::getPriority(4), 'EventPriority::LOW'); - $this->assertEquals(EventPriority::getPriority(3), 'EventPriority::NORMAL'); - $this->assertEquals(EventPriority::getPriority(2), 'EventPriority::HIGH'); - $this->assertEquals(EventPriority::getPriority(1), 'EventPriority::HIGHEST'); - $this->assertEquals(EventPriority::getPriority(0), 'EventPriority::MONITOR'); + $this->assertEquals(Priority::getPriority(5), 'Priority::LOWEST'); + $this->assertEquals(Priority::getPriority(4), 'Priority::LOW'); + $this->assertEquals(Priority::getPriority(3), 'Priority::NORMAL'); + $this->assertEquals(Priority::getPriority(2), 'Priority::HIGH'); + $this->assertEquals(Priority::getPriority(1), 'Priority::HIGHEST'); + $this->assertEquals(Priority::getPriority(0), 'Priority::MONITOR'); } public function testGetInvalidPriority() { - $this->assertFalse(EventPriority::getPriority(99)); + $this->assertFalse(Priority::getPriority(99)); } public function testHighestPriority() { - $this->assertEquals(EventPriority::getHighestPriority(), EventPriority::MONITOR); + $this->assertEquals(Priority::getHighestPriority(), Priority::MONITOR); } public function testLowestPriority() { - $this->assertEquals(EventPriority::getLowestPriority(), EventPriority::LOWEST); + $this->assertEquals(Priority::getLowestPriority(), Priority::LOWEST); } } diff --git a/test/events/event_coreStartEventTest.php b/test/events/event_coreStartEventTest.php index 049a1cb..f5a3354 100644 --- a/test/events/event_coreStartEventTest.php +++ b/test/events/event_coreStartEventTest.php @@ -35,7 +35,7 @@ */ use FuzeWorks\Factory; use FuzeWorks\Events; -use FuzeWorks\EventPriority; +use FuzeWorks\Priority; /** * Class CoreStartEventTest. @@ -50,7 +50,7 @@ class coreStartEventTest extends CoreTestAbstract $mock = $this->getMockBuilder(MockStartEvent::class)->setMethods(['mockMethod'])->getMock(); $mock->expects($this->once())->method('mockMethod'); - Events::addListener(array($mock, 'mockMethod'), 'coreStartEvent', EventPriority::NORMAL); + Events::addListener(array($mock, 'mockMethod'), 'coreStartEvent', Priority::NORMAL); $factory = new Factory; $factory->init(); } diff --git a/test/events/event_pluginGetEventTest.php b/test/events/event_pluginGetEventTest.php index 5f83729..49514df 100644 --- a/test/events/event_pluginGetEventTest.php +++ b/test/events/event_pluginGetEventTest.php @@ -35,7 +35,7 @@ */ use FuzeWorks\Factory; use FuzeWorks\Events; -use FuzeWorks\EventPriority; +use FuzeWorks\Priority; /** * Class pluginGetEventTest. @@ -51,7 +51,7 @@ class pluginGetEventTest extends CoreTestAbstract Events::addListener( function($event){$event->setCancelled(true);return $event;}, 'pluginGetEvent', - EventPriority::NORMAL); + Priority::NORMAL); // And fire the event $this->assertFalse(Factory::getInstance()->plugins->get('test')); @@ -66,7 +66,7 @@ class pluginGetEventTest extends CoreTestAbstract Events::addListener( function($event){$event->setPlugin('test_string');return $event;}, 'pluginGetEvent', - EventPriority::NORMAL); + Priority::NORMAL); // And fire the event $this->assertEquals('test_string', Factory::getInstance()->plugins->get('test'));