JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
metaform: fix download_tar() (stylus not less)
[wfpl.git] / atexit.php
1 <?php
2
3 # this file is much like register_shutdown_function(), except:
4 #
5 # 1.    it uses the standard name you know and love
6 #
7 # 2.    wfpl will call it before calling display_messages() for you, or before
8 #       calling session_save_messages() (when it's about to redirect.
9
10 $GLOBALS['wfpl_atexit_queue'] = array();
11
12 # your passed function will be called by run.php just before display_messages
13 # (or right before an http redirect)
14 #
15 # order is fifo
16 function atexit($func, $args) {
17         $GLOBALS['wfpl_atexit_queue'][] = array($func, $args);
18 }
19
20 # call the functions queued up by atexit()
21 # atexit() can be called from one of these functions (even the last)
22 function atexit_now() {
23         while(count($GLOBALS['wfpl_atexit_queue'])) {
24                 list($func, $args) = array_shift($GLOBALS['wfpl_atexit_queue']);
25                 call_user_func_array($func, $args);
26         }
27 }
28
29 # for those cases where display_messages() and session_save_messages() don't
30 # get called automatically by wfpl:
31 register_shutdown_function("atexit_now");