MediaWiki  REL1_24
PoolCounterWorkViaCallback.php
Go to the documentation of this file.
00001 <?php
00028 class PoolCounterWorkViaCallback extends PoolCounterWork {
00030     protected $doWork;
00032     protected $doCachedWork;
00034     protected $fallback;
00036     protected $error;
00037 
00052     public function __construct( $type, $key, array $callbacks ) {
00053         parent::__construct( $type, $key );
00054         foreach ( array( 'doWork', 'doCachedWork', 'fallback', 'error' ) as $name ) {
00055             if ( isset( $callbacks[$name] ) ) {
00056                 if ( !is_callable( $callbacks[$name] ) ) {
00057                     throw new MWException( "Invalid callback provided for '$name' function." );
00058                 }
00059                 $this->$name = $callbacks[$name];
00060             }
00061         }
00062         if ( !isset( $this->doWork ) ) {
00063             throw new MWException( "No callback provided for 'doWork' function." );
00064         }
00065         $this->cacheable = isset( $this->doCachedWork );
00066     }
00067 
00068     public function doWork() {
00069         return call_user_func_array( $this->doWork, array() );
00070     }
00071 
00072     public function getCachedWork() {
00073         if ( $this->doCachedWork ) {
00074             return call_user_func_array( $this->doCachedWork, array() );
00075         }
00076         return false;
00077     }
00078 
00079     public function fallback() {
00080         if ( $this->fallback ) {
00081             return call_user_func_array( $this->fallback, array() );
00082         }
00083         return false;
00084     }
00085 
00086     public function error( $status ) {
00087         if ( $this->error ) {
00088             return call_user_func_array( $this->error, array( $status ) );
00089         }
00090         return false;
00091     }
00092 }