MediaWiki  REL1_24
Cdb.php
Go to the documentation of this file.
00001 <?php
00028 abstract class CdbReader {
00032     protected $handle;
00033 
00041     public static function open( $fileName ) {
00042         return self::haveExtension() ?
00043             new CdbReaderDBA( $fileName ) :
00044             new CdbReaderPHP( $fileName );
00045     }
00046 
00052     public static function haveExtension() {
00053         if ( !function_exists( 'dba_handlers' ) ) {
00054             return false;
00055         }
00056         $handlers = dba_handlers();
00057         if ( !in_array( 'cdb', $handlers ) || !in_array( 'cdb_make', $handlers ) ) {
00058             return false;
00059         }
00060 
00061         return true;
00062     }
00063 
00069     abstract public function __construct( $fileName );
00070 
00074     abstract public function close();
00075 
00081     abstract public function get( $key );
00082 }
00083 
00088 abstract class CdbWriter {
00092     protected $handle;
00093 
00098     protected $realFileName;
00099 
00104     protected $tmpFileName;
00105 
00114     public static function open( $fileName ) {
00115         return CdbReader::haveExtension() ?
00116             new CdbWriterDBA( $fileName ) :
00117             new CdbWriterPHP( $fileName );
00118     }
00119 
00125     abstract public function __construct( $fileName );
00126 
00132     abstract public function set( $key, $value );
00133 
00138     abstract public function close();
00139 
00143     public function __destruct() {
00144         if ( isset( $this->handle ) ) {
00145             $this->close();
00146         }
00147     }
00148 
00153     protected function isWindows() {
00154         return substr( php_uname(), 0, 7 ) == 'Windows';
00155     }
00156 }
00157 
00162 class CdbException extends Exception {
00163 }