MediaWiki  REL1_22
ScopedCallback.php
Go to the documentation of this file.
00001 <?php
00028 class ScopedCallback {
00030     protected $callback;
00031 
00036     public function __construct( $callback ) {
00037         if ( !is_callable( $callback ) ) {
00038             throw new MWException( "Provided callback is not valid." );
00039         }
00040         $this->callback = $callback;
00041     }
00042 
00049     public static function consume( ScopedCallback &$sc = null ) {
00050         $sc = null;
00051     }
00052 
00058     public static function cancel( ScopedCallback &$sc = null ) {
00059         if ( $sc ) {
00060             $sc->callback = null;
00061         }
00062         $sc = null;
00063     }
00064 
00068     function __destruct() {
00069         if ( $this->callback !== null ) {
00070             call_user_func( $this->callback );
00071         }
00072     }
00073 }