mirror of
				https://github.com/Mibew/mibew.git
				synced 2025-11-04 04:15:19 +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
 | 
							// Following code wait for trigger user error, which converts by PHPUnit to an
 | 
				
			||||||
		// Exception
 | 
							// Exception
 | 
				
			||||||
		try{
 | 
							try{
 | 
				
			||||||
			$dispatcher->triggerEvent('unregistered_event', array());
 | 
								$dispatcher->triggerEvent('unregistered_event');
 | 
				
			||||||
			$this->fail("Error expected!");
 | 
								$this->fail("Error expected!");
 | 
				
			||||||
		} catch(Exception $e) {}
 | 
							} catch(Exception $e) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Try to thrigger registered event
 | 
							// Try to trigger registered event
 | 
				
			||||||
		// Wait for exception thrown by
 | 
							$test_array = array();
 | 
				
			||||||
		// Phpunit_autotest_plugin_managerPlugin::testEventListener()
 | 
							$dispatcher->triggerEvent('some_another_test_event', $test_array);
 | 
				
			||||||
		try{
 | 
							$this->assertEquals('some_test_value', $test_array['test']);
 | 
				
			||||||
			$dispatcher->triggerEvent('some_another_test_event', array());
 | 
					 | 
				
			||||||
			$this->fail("Exception excpected!");
 | 
					 | 
				
			||||||
		} catch(Exception $e) {}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -28,8 +28,8 @@ Class Phpunit_autotest_plugin_managerPlugin extends Plugin{
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function testEventListener($vars) {
 | 
						public function testEventListener(&$vars) {
 | 
				
			||||||
		throw new Exception();
 | 
							$vars['test'] = 'some_test_value';
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function __construct(){
 | 
						public function __construct(){
 | 
				
			||||||
 | 
				
			|||||||
@ -139,10 +139,10 @@ Class EventDispatcher {
 | 
				
			|||||||
	 * Triggers the event
 | 
						 * Triggers the event
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * @param string $event_name Event's name
 | 
						 * @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
 | 
						 * @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
 | 
							// Check event exists
 | 
				
			||||||
		if (! array_key_exists($event_name, $this->events)) {
 | 
							if (! array_key_exists($event_name, $this->events)) {
 | 
				
			||||||
			trigger_error("Event '{$event_name}' does not exists!", E_USER_WARNING);
 | 
								trigger_error("Event '{$event_name}' does not exists!", E_USER_WARNING);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user