MediaWiki  REL1_24
HashBagOStuff.php
Go to the documentation of this file.
00001 <?php
00030 class HashBagOStuff extends BagOStuff {
00032     protected $bag;
00033 
00034     function __construct() {
00035         $this->bag = array();
00036     }
00037 
00042     protected function expire( $key ) {
00043         $et = $this->bag[$key][1];
00044 
00045         if ( ( $et == 0 ) || ( $et > time() ) ) {
00046             return false;
00047         }
00048 
00049         $this->delete( $key );
00050 
00051         return true;
00052     }
00053 
00059     function get( $key, &$casToken = null ) {
00060         if ( !isset( $this->bag[$key] ) ) {
00061             return false;
00062         }
00063 
00064         if ( $this->expire( $key ) ) {
00065             return false;
00066         }
00067 
00068         $casToken = serialize( $this->bag[$key][0] );
00069 
00070         return $this->bag[$key][0];
00071     }
00072 
00079     function set( $key, $value, $exptime = 0 ) {
00080         $this->bag[$key] = array( $value, $this->convertExpiry( $exptime ) );
00081         return true;
00082     }
00083 
00091     function cas( $casToken, $key, $value, $exptime = 0 ) {
00092         if ( serialize( $this->get( $key ) ) === $casToken ) {
00093             return $this->set( $key, $value, $exptime );
00094         }
00095 
00096         return false;
00097     }
00098 
00104     function delete( $key, $time = 0 ) {
00105         if ( !isset( $this->bag[$key] ) ) {
00106             return false;
00107         }
00108 
00109         unset( $this->bag[$key] );
00110 
00111         return true;
00112     }
00113 }