Commit ef6076b2 by Taylor Otwell

added event queues.

parent af9f875e
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
- Fixed bug when using many-to-many relationships on non-default database connection. - Fixed bug when using many-to-many relationships on non-default database connection.
- Added true reflection based IoC to container. - Added true reflection based IoC to container.
- Added `Request::route()->controller` and `Request::route()->controller_action`. - Added `Request::route()->controller` and `Request::route()->controller_action`.
- Added `Event::queue`, `Event::flusher`, and `Event::flush` methods to Event class.
<a name="upgrade-3.2"></a> <a name="upgrade-3.2"></a>
## Upgrading From 3.1 ## Upgrading From 3.1
......
...@@ -10,6 +10,20 @@ class Event { ...@@ -10,6 +10,20 @@ class Event {
public static $events = array(); public static $events = array();
/** /**
* The queued events waiting for flushing.
*
* @var array
*/
public static $queued = array();
/**
* All of the registered queue flusher callbacks.
*
* @var array
*/
public static $flushers = array();
/**
* Determine if an event has any registered listeners. * Determine if an event has any registered listeners.
* *
* @param string $event * @param string $event
...@@ -55,6 +69,31 @@ class Event { ...@@ -55,6 +69,31 @@ class Event {
} }
/** /**
* Add an item to an event queue for processing.
*
* @param string $queue
* @param string $key
* @param mixed $data
* @return void
*/
public static function queue($queue, $key, $data)
{
static::$queued[$queue][$key] = $data;
}
/**
* Register a queue flusher callback.
*
* @param string $queue
* @param mixed $callback
* @return void
*/
public static function flusher($queue, $callback)
{
static::$flushers[$queue][] = $callback;
}
/**
* Clear all event listeners for a given event. * Clear all event listeners for a given event.
* *
* @param string $event * @param string $event
...@@ -100,6 +139,28 @@ class Event { ...@@ -100,6 +139,28 @@ class Event {
} }
/** /**
* Flush an event queue, firing the flusher for each payload.
*
* @param string $queue
* @return void
*/
public static function flush($queue)
{
foreach (static::$flushers[$queue] as $flusher)
{
// We will simply spin through each payload registered for the event and
// fire the flusher, passing each payloads as we go. This allows all
// the events on the queue to be processed by the flusher easily.
foreach (static::$queued[$queue] as $key => $payload)
{
array_unshift($payload, $key);
call_user_func_array($flusher, $payload);
}
}
}
/**
* Fire an event so that all listeners are called. * Fire an event so that all listeners are called.
* *
* <code> * <code>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment