b0a90c31d675c3dc1ebf7d01b214ef89b5a0dc96
3 * Native CDB file reader and writer.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Write to a CDB file.
25 * Native and pure PHP implementations are provided.
26 * http://cr.yp.to/cdb.html
28 abstract class CdbWriter
{
35 * File we'll be writing to when we're done
38 protected $realFileName;
41 * File we write to temporarily until we're done
44 protected $tmpFileName;
47 * Open a writer and return a subclass instance.
48 * The user must have write access to the directory, for temporary file creation.
50 * @param string $fileName
52 * @return CdbWriterDBA|CdbWriterPHP
54 public static function open( $fileName ) {
55 return CdbReader
::haveExtension() ?
56 new CdbWriterDBA( $fileName ) :
57 new CdbWriterPHP( $fileName );
61 * Create the object and open the file
63 * @param string $fileName
65 abstract public function __construct( $fileName );
68 * Set a key to a given value. The value will be converted to string.
70 * @param string $value
72 abstract public function set( $key, $value );
75 * Close the writer object. You should call this function before the object
76 * goes out of scope, to write out the final hashtables.
78 abstract public function close();
81 * If the object goes out of scope, close it for sanity
83 public function __destruct() {
84 if ( isset( $this->handle
) ) {
90 * Are we running on Windows?
93 protected function isWindows() {
94 return substr( php_uname(), 0, 7 ) == 'Windows';