Add some events to Eloquent models.
This commit is contained in:
@@ -108,14 +108,17 @@ class Event {
|
||||
*
|
||||
* // Fire the "start" event passing an array of parameters
|
||||
* $responses = Event::fire('start', array('Laravel', 'Framework'));
|
||||
*
|
||||
* // Fire multiple events with the same parameters
|
||||
* $responses = Event::fire(array('start', 'loading'), $parameters);
|
||||
* </code>
|
||||
*
|
||||
* @param string $event
|
||||
* @param array $parameters
|
||||
* @param bool $halt
|
||||
* @param string|array $event
|
||||
* @param array $parameters
|
||||
* @param bool $halt
|
||||
* @return array
|
||||
*/
|
||||
public static function fire($event, $parameters = array(), $halt = false)
|
||||
public static function fire($events, $parameters = array(), $halt = false)
|
||||
{
|
||||
$responses = array();
|
||||
|
||||
@@ -124,24 +127,27 @@ class Event {
|
||||
// If the event has listeners, we will simply iterate through them and call
|
||||
// each listener, passing in the parameters. We will add the responses to
|
||||
// an array of event responses and return the array.
|
||||
if (static::listeners($event))
|
||||
foreach ((array) $events as $event)
|
||||
{
|
||||
foreach (static::$events[$event] as $callback)
|
||||
if (static::listeners($event))
|
||||
{
|
||||
$response = call_user_func_array($callback, $parameters);
|
||||
|
||||
// If the event is set to halt, we will return the first response
|
||||
// that is not null. This allows the developer to easily stack
|
||||
// events but still get the first valid response.
|
||||
if ($halt and ! is_null($response))
|
||||
foreach (static::$events[$event] as $callback)
|
||||
{
|
||||
return $response;
|
||||
}
|
||||
$response = call_user_func_array($callback, $parameters);
|
||||
|
||||
// After the handler has been called, we'll add the response to
|
||||
// an array of responses and return the array to the caller so
|
||||
// all of the responses can be easily examined.
|
||||
$responses[] = $response;
|
||||
// If the event is set to halt, we will return the first response
|
||||
// that is not null. This allows the developer to easily stack
|
||||
// events but still get the first valid response.
|
||||
if ($halt and ! is_null($response))
|
||||
{
|
||||
return $response;
|
||||
}
|
||||
|
||||
// After the handler has been called, we'll add the response to
|
||||
// an array of responses and return the array to the caller so
|
||||
// all of the responses can be easily examined.
|
||||
$responses[] = $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user