Created
April 12, 2013 15:04
-
-
Save ringmaster/5372683 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add objects or functions to the post-processing queue, executed via self::process_queue() | |
* @param QueryRecord|Callable $fn A QueryRecord to call ->update() on, or a function to execute | |
* @param null|string $name An index to save the queue under, defaults to the SPL object hash for objects | |
*/ | |
public static function queue($fn, $name = null) | |
{ | |
if(is_null($name) && is_object($fn)) { | |
$name = spl_object_hash($fn); | |
} | |
if(is_object($name) && is_object($fn)) { | |
$name = spl_object_hash($name); | |
} | |
if(is_null($name)) { | |
self::$write_queue[] = $fn; | |
} | |
else { | |
self::$write_queue[$name] = $fn; | |
} | |
} | |
/** | |
* Call update() on QueryRecords or execute the function queued with self::queue() | |
*/ | |
public static function process_queue() | |
{ | |
foreach(self::$write_queue as $fn) { | |
if($fn instanceof QueryRecord) { | |
$fn->update(); | |
} | |
else { | |
$fn(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment