handle = dba_open( $fileName, 'r-', 'cdb' ); if ( !$this->handle ) { throw new MWException( 'Unable to open CDB file "' . $fileName . '"' ); } } function close() { if ( isset( $this->handle ) ) { dba_close( $this->handle ); } unset( $this->handle ); } function get( $key ) { return dba_fetch( $key, $this->handle ); } } /** * Writer class which uses the DBA extension */ class CdbWriter_DBA { var $handle, $realFileName, $tmpFileName; function __construct( $fileName ) { $this->realFileName = $fileName; $this->tmpFileName = $fileName . '.tmp.' . mt_rand( 0, 0x7fffffff ); $this->handle = dba_open( $this->tmpFileName, 'n', 'cdb_make' ); if ( !$this->handle ) { throw new MWException( 'Unable to open CDB file for write "' . $fileName . '"' ); } } function set( $key, $value ) { return dba_insert( $key, $value, $this->handle ); } function close() { if ( isset( $this->handle ) ) { dba_close( $this->handle ); } if ( wfIsWindows() ) { unlink( $this->realFileName ); } if ( !rename( $this->tmpFileName, $this->realFileName ) ) { throw new MWException( 'Unable to move the new CDB file into place.' ); } unset( $this->handle ); } function __destruct() { if ( isset( $this->handle ) ) { $this->close(); } } }