MediaWiki
REL1_19
|
00001 <?php 00043 abstract class BagOStuff { 00044 private $debugMode = false; 00045 00049 public function setDebug( $bool ) { 00050 $this->debugMode = $bool; 00051 } 00052 00053 /* *** THE GUTS OF THE OPERATION *** */ 00054 /* Override these with functional things in subclasses */ 00055 00062 abstract public function get( $key ); 00063 00070 abstract public function set( $key, $value, $exptime = 0 ); 00071 00077 abstract public function delete( $key, $time = 0 ); 00078 00079 public function lock( $key, $timeout = 0 ) { 00080 /* stub */ 00081 return true; 00082 } 00083 00084 public function unlock( $key ) { 00085 /* stub */ 00086 return true; 00087 } 00088 00089 public function keys() { 00090 /* stub */ 00091 return array(); 00092 } 00093 00103 public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) { 00104 // stub 00105 return false; 00106 } 00107 00108 /* *** Emulated functions *** */ 00109 00110 public function add( $key, $value, $exptime = 0 ) { 00111 if ( !$this->get( $key ) ) { 00112 $this->set( $key, $value, $exptime ); 00113 00114 return true; 00115 } 00116 } 00117 00118 public function replace( $key, $value, $exptime = 0 ) { 00119 if ( $this->get( $key ) !== false ) { 00120 $this->set( $key, $value, $exptime ); 00121 } 00122 } 00123 00129 public function incr( $key, $value = 1 ) { 00130 if ( !$this->lock( $key ) ) { 00131 return null; 00132 } 00133 00134 $value = intval( $value ); 00135 00136 if ( ( $n = $this->get( $key ) ) !== false ) { 00137 $n += $value; 00138 $this->set( $key, $n ); // exptime? 00139 } 00140 $this->unlock( $key ); 00141 00142 return $n; 00143 } 00144 00145 public function decr( $key, $value = 1 ) { 00146 return $this->incr( $key, - $value ); 00147 } 00148 00149 public function debug( $text ) { 00150 if ( $this->debugMode ) { 00151 $class = get_class( $this ); 00152 wfDebug( "$class debug: $text\n" ); 00153 } 00154 } 00155 00159 protected function convertExpiry( $exptime ) { 00160 if ( ( $exptime != 0 ) && ( $exptime < 86400 * 3650 /* 10 years */ ) ) { 00161 return time() + $exptime; 00162 } else { 00163 return $exptime; 00164 } 00165 } 00166 } 00167 00168