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 * Read from a CDB file.
28 * Native and pure PHP implementations are provided.
29 * http://cr.yp.to/cdb.html
31 abstract class Reader {
38 * Open a file and return a subclass instance
40 * @param string $fileName
44 public static function open( $fileName ) {
45 return self::haveExtension() ?
46 new Reader\DBA( $fileName ) :
47 new Reader\PHP( $fileName );
51 * Returns true if the native extension is available
55 public static function haveExtension() {
56 if ( !function_exists( 'dba_handlers' ) ) {
59 $handlers = dba_handlers();
60 if ( !in_array( 'cdb', $handlers ) || !in_array( 'cdb_make', $handlers ) ) {
68 * Create the object and open the file
70 * @param string $fileName
72 abstract public function __construct( $fileName );
75 * Close the file. Optional, you can just let the variable go out of scope.
77 abstract public function close();
80 * Get a value with a given key. Only string values are supported.
84 abstract public function get( $key );
87 * Check whether key exists
91 abstract public function exists( $key );
96 abstract public function firstkey();
101 abstract public function nextkey();