mirror of
				https://github.com/Mibew/tray.git
				synced 2025-10-03 00:03:34 +03:00 
			
		
		
		
	Pass arguments to EventDispatcher::triggerEvent by reference
This commit is contained in:
		
							parent
							
								
									17369b2f14
								
							
						
					
					
						commit
						f4e87f5303
					
				| @ -139,17 +139,14 @@ class EventDispatcherTest extends PHPUnit_Framework_TestCase { | ||||
| 		// Following code wait for trigger user error, which converts by PHPUnit to an
 | ||||
| 		// Exception
 | ||||
| 		try{ | ||||
| 			$dispatcher->triggerEvent('unregistered_event', array()); | ||||
| 			$dispatcher->triggerEvent('unregistered_event'); | ||||
| 			$this->fail("Error expected!"); | ||||
| 		} catch(Exception $e) {} | ||||
| 
 | ||||
| 		// Try to thrigger registered event
 | ||||
| 		// Wait for exception thrown by
 | ||||
| 		// Phpunit_autotest_plugin_managerPlugin::testEventListener()
 | ||||
| 		try{ | ||||
| 			$dispatcher->triggerEvent('some_another_test_event', array()); | ||||
| 			$this->fail("Exception excpected!"); | ||||
| 		} catch(Exception $e) {} | ||||
| 		// Try to trigger registered event
 | ||||
| 		$test_array = array(); | ||||
| 		$dispatcher->triggerEvent('some_another_test_event', $test_array); | ||||
| 		$this->assertEquals('some_test_value', $test_array['test']); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -28,8 +28,8 @@ Class Phpunit_autotest_plugin_managerPlugin extends Plugin{ | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	public function testEventListener($vars) { | ||||
| 		throw new Exception(); | ||||
| 	public function testEventListener(&$vars) { | ||||
| 		$vars['test'] = 'some_test_value'; | ||||
| 	} | ||||
| 
 | ||||
| 	public function __construct(){ | ||||
|  | ||||
| @ -139,10 +139,10 @@ Class EventDispatcher { | ||||
| 	 * Triggers the event | ||||
| 	 * | ||||
| 	 * @param string $event_name Event's name | ||||
| 	 * @param array $arguments Arguments passed to listener | ||||
| 	 * @param array &$arguments Arguments passed to listener | ||||
| 	 * @return boolean true on success or false on failure | ||||
| 	 */ | ||||
| 	public function triggerEvent($event_name, $arguments = array()){ | ||||
| 	public function triggerEvent($event_name, &$arguments = array()){ | ||||
| 		// Check event exists
 | ||||
| 		if (! array_key_exists($event_name, $this->events)) { | ||||
| 			trigger_error("Event '{$event_name}' does not exists!", E_USER_WARNING); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user