Documentation and type hinting.
[lhc/web/wiklou.git] / includes / Cdb.php
index 20cb7e3..6047748 100644 (file)
@@ -1,4 +1,9 @@
 <?php
+/**
+ * Native CDB file reader and writer
+ *
+ * @file
+ */
 
 /**
  * Read from a CDB file.
@@ -13,7 +18,7 @@ abstract class CdbReader {
                if ( self::haveExtension() ) {
                        return new CdbReader_DBA( $fileName );
                } else {
-                       wfDebug( 'Warning: no dba extension found, using emulation.' );
+                       wfDebug( "Warning: no dba extension found, using emulation.\n" );
                        return new CdbReader_PHP( $fileName );
                }
        }
@@ -61,7 +66,7 @@ abstract class CdbWriter {
                if ( CdbReader::haveExtension() ) {
                        return new CdbWriter_DBA( $fileName );
                } else {
-                       wfDebug( 'Warning: no dba extension found, using emulation.' );
+                       wfDebug( "Warning: no dba extension found, using emulation.\n" );
                        return new CdbWriter_PHP( $fileName );
                }
        }
@@ -93,12 +98,13 @@ class CdbReader_DBA {
        function __construct( $fileName ) {
                $this->handle = dba_open( $fileName, 'r-', 'cdb' );
                if ( !$this->handle ) {
-                       throw new MWException( 'Unable to open DB file "' . $fileName . '"' );
+                       throw new MWException( 'Unable to open CDB file "' . $fileName . '"' );
                }
        }
 
        function close() {
-               dba_close( $this->handle );
+               if( isset($this->handle) )
+                       dba_close( $this->handle );
                unset( $this->handle );
        }
 
@@ -119,7 +125,7 @@ class CdbWriter_DBA {
                $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 DB file for write "' . $fileName . '"' );
+                       throw new MWException( 'Unable to open CDB file for write "' . $fileName . '"' );
                }
        }
 
@@ -128,7 +134,8 @@ class CdbWriter_DBA {
        }
 
        function close() {
-               dba_close( $this->handle );
+               if( isset($this->handle) )
+                       dba_close( $this->handle );
                if ( wfIsWindows() ) {
                        unlink( $this->realFileName );
                }