MediaWiki
REL1_24
|
00001 <?php 00026 class CdbReaderDBA extends CdbReader { 00027 public function __construct( $fileName ) { 00028 $this->handle = dba_open( $fileName, 'r-', 'cdb' ); 00029 if ( !$this->handle ) { 00030 throw new CdbException( 'Unable to open CDB file "' . $fileName . '"' ); 00031 } 00032 } 00033 00034 public function close() { 00035 if ( isset( $this->handle ) ) { 00036 dba_close( $this->handle ); 00037 } 00038 unset( $this->handle ); 00039 } 00040 00041 public function get( $key ) { 00042 return dba_fetch( $key, $this->handle ); 00043 } 00044 } 00045 00049 class CdbWriterDBA extends CdbWriter { 00050 public function __construct( $fileName ) { 00051 $this->realFileName = $fileName; 00052 $this->tmpFileName = $fileName . '.tmp.' . mt_rand( 0, 0x7fffffff ); 00053 $this->handle = dba_open( $this->tmpFileName, 'n', 'cdb_make' ); 00054 if ( !$this->handle ) { 00055 throw new CdbException( 'Unable to open CDB file for write "' . $fileName . '"' ); 00056 } 00057 } 00058 00059 public function set( $key, $value ) { 00060 return dba_insert( $key, $value, $this->handle ); 00061 } 00062 00063 public function close() { 00064 if ( isset( $this->handle ) ) { 00065 dba_close( $this->handle ); 00066 } 00067 if ( $this->isWindows() ) { 00068 unlink( $this->realFileName ); 00069 } 00070 if ( !rename( $this->tmpFileName, $this->realFileName ) ) { 00071 throw new CdbException( 'Unable to move the new CDB file into place.' ); 00072 } 00073 unset( $this->handle ); 00074 } 00075 }