00001 <?php
00002
00003
# Pure virtual parent
00004 class HistoryBlob
00005 {
00006 function
setMeta() {}
00007 function
getMeta() {}
00008 function
addItem() {}
00009 function
getItem() {}
00010 }
00011
00012
# The real object
00013 class ConcatenatedGzipHistoryBlob
00014 {
00015 var
$mVersion = 0, $mCompressed =
false, $mItems = array();
00016
00017 function
HistoryBlob() {
00018
if ( !function_exists( 'gzdeflate' ) ) {
00019 die(
"Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" );
00020 }
00021 }
00022
00023 function
setMeta( $metaData ) {
00024 $this->
uncompress();
00025 $this->mItems['meta'] = $metaData;
00026 }
00027
00028 function
getMeta() {
00029 $this->
uncompress();
00030
return $this->mItems['meta'];
00031 }
00032
00033 function
addItem( $text ) {
00034 $this->
uncompress();
00035 $this->mItems[md5($text)] = $text;
00036 }
00037
00038 function
getItem( $hash ) {
00039 $this->
compress();
00040
return $this->mItems[$hash];
00041 }
00042
00043 function
compress() {
00044
if ( !$this->mCompressed ) {
00045 $this->mItems = gzdeflate( serialize( $this->mItems ) );
00046 $this->mCompressed =
true;
00047 }
00048 }
00049
00050 function
uncompress() {
00051
if ( $this->mCompressed ) {
00052 $this->mItems = unserialize( gzinflate( $this->mItems ) );
00053 }
00054 }
00055
00056 function
__sleep() {
00057
compress();
00058 }
00059
00060 function
__wakeup() {
00061
uncompress();
00062 }
00063 }
00064 ?>