Browse Source

Added override and clear methods to event class.

Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
Taylor Otwell 12 years ago
parent
commit
fdcebc1bcb
1 changed files with 25 additions and 0 deletions
  1. 25 0
      laravel/event.php

+ 25 - 0
laravel/event.php

@@ -40,6 +40,31 @@ class Event {
 		static::$events[$event][] = $callback;
 		static::$events[$event][] = $callback;
 	}
 	}
 
 
+	/**
+	 * Override all callbacks for a given event with a new callback.
+	 *
+	 * @param  string  $event
+	 * @param  mixed   $callback
+	 * @return void
+	 */
+	public static function override($event, $callback)
+	{
+		static::clear($event);
+
+		static::listen($event, $callback);
+	}
+
+	/**
+	 * Clear all event listeners for a given event.
+	 *
+	 * @param  string  $event
+	 * @return void
+	 */
+	public static function clear($event)
+	{
+		static::$events[$event] = array();
+	}
+
 	/**
 	/**
 	 * Fire an event and return the first response.
 	 * Fire an event and return the first response.
 	 *
 	 *