6 * Native CDB file reader and writer.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
27 * Write to a CDB file.
28 * Native and pure PHP implementations are provided.
29 * http://cr.yp.to/cdb.html
31 abstract class Writer {
38 * File we'll be writing to when we're done
41 protected $realFileName;
44 * File we write to temporarily until we're done
47 protected $tmpFileName;
50 * Open a writer and return a subclass instance.
51 * The user must have write access to the directory, for temporary file creation.
53 * @param string $fileName
57 public static function open( $fileName ) {
58 return Reader::haveExtension() ?
59 new Writer\DBA( $fileName ) :
60 new Writer\PHP( $fileName );
64 * Create the object and open the file
66 * @param string $fileName
68 abstract public function __construct( $fileName );
71 * Set a key to a given value. The value will be converted to string.
73 * @param string $value
75 abstract public function set( $key, $value );
78 * Close the writer object. You should call this function before the object
79 * goes out of scope, to write out the final hashtables.
81 abstract public function close();
84 * If the object goes out of scope, close it for sanity
86 public function __destruct() {
87 if ( isset( $this->handle ) ) {
93 * Are we running on Windows?
96 protected function isWindows() {
97 return strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN';