*
* @param $s string
*
- * @return
+ * @return int
*/
public static function hash( $s ) {
$h = 5381;
/** The filename */
var $fileName;
- /** The file handle */
- var $handle;
-
/* number of hash slots searched under this key */
var $loop;
/**
* @param $fileName string
- * @throws MWException
+ * @throws CdbException
*/
- function __construct( $fileName ) {
+ public function __construct( $fileName ) {
$this->fileName = $fileName;
$this->handle = fopen( $fileName, 'rb' );
if ( !$this->handle ) {
- throw new MWException( 'Unable to open CDB file "' . $this->fileName . '".' );
+ throw new CdbException( 'Unable to open CDB file "' . $this->fileName . '".' );
}
$this->findStart();
}
- function close() {
+ public function close() {
if ( isset( $this->handle ) ) {
fclose( $this->handle );
}
}
/**
- * @throws MWException
+ * @throws CdbException
* @param $length
* @param $pos
* @return string
protected function read( $length, $pos ) {
if ( fseek( $this->handle, $pos ) == -1 ) {
// This can easily happen if the internal pointers are incorrect
- throw new MWException(
+ throw new CdbException(
'Seek failed, file "' . $this->fileName . '" may be corrupted.' );
}
$buf = fread( $this->handle, $length );
if ( $buf === false || strlen( $buf ) !== $length ) {
- throw new MWException(
+ throw new CdbException(
'Read from CDB file failed, file "' . $this->fileName . '" may be corrupted.' );
}
/**
* Unpack an unsigned integer and throw an exception if it needs more than 31 bits
* @param $s
- * @throws MWException
+ * @throws CdbException
* @return mixed
*/
protected function unpack31( $s ) {
$data = unpack( 'V', $s );
if ( $data[1] > 0x7fffffff ) {
- throw new MWException(
+ throw new CdbException(
'Error in CDB file "' . $this->fileName . '", integer too big.' );
}
* CDB writer class
*/
class CdbWriterPHP extends CdbWriter {
- var $handle, $realFileName, $tmpFileName;
-
var $hplist;
var $numentries, $pos;
/**
* @param $fileName string
*/
- function __construct( $fileName ) {
+ public function __construct( $fileName ) {
$this->realFileName = $fileName;
$this->tmpFileName = $fileName . '.tmp.' . mt_rand( 0, 0x7fffffff );
$this->handle = fopen( $this->tmpFileName, 'wb' );
}
}
- function __destruct() {
- if ( isset( $this->handle ) ) {
- $this->close();
- }
- }
-
/**
- * @param $key
- * @param $value
- * @return
+ * @param string $key
+ * @param string $value
*/
public function set( $key, $value ) {
if ( strval( $key ) === '' ) {
}
/**
- * @throws MWException
+ * @throws CdbException
*/
public function close() {
$this->finish();
if ( isset( $this->handle ) ) {
fclose( $this->handle );
}
- if ( wfIsWindows() && file_exists( $this->realFileName ) ) {
+ if ( $this->isWindows() && file_exists( $this->realFileName ) ) {
unlink( $this->realFileName );
}
if ( !rename( $this->tmpFileName, $this->realFileName ) ) {
}
/**
- * @throws MWException
+ * @throws CdbException
* @param $buf
*/
protected function write( $buf ) {
}
/**
- * @throws MWException
+ * @throws CdbException
* @param $len
*/
protected function posplus( $len ) {
}
/**
- * @throws MWException
+ * @throws CdbException
* @param $keylen
* @param $datalen
*/
}
/**
- * @throws MWException
+ * @throws CdbException
*/
protected function finish() {
// Hack for DBA cross-check
* Clean up the temp file and throw an exception
*
* @param $msg string
- * @throws MWException
+ * @throws CdbException
*/
protected function throwException( $msg ) {
if ( $this->handle ) {
fclose( $this->handle );
unlink( $this->tmpFileName );
}
- throw new MWException( $msg );
+ throw new CdbException( $msg );
}
}