From 9e971edd7fa6715de74ba1beecd48e7cd7390196 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Sun, 8 Apr 2007 14:24:39 +0000 Subject: two php5 only classes... first stage of re-write --- lib/class/config.class.php | 111 ++++++++++++++++++++++++++++++ lib/class/dba.class.php | 168 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 279 insertions(+) create mode 100644 lib/class/config.class.php create mode 100644 lib/class/dba.class.php (limited to 'lib') diff --git a/lib/class/config.class.php b/lib/class/config.class.php new file mode 100644 index 00000000..dbb75f41 --- /dev/null +++ b/lib/class/config.class.php @@ -0,0 +1,111 @@ +_local[$name]; + } + else { + return self::$_global[$name]; + } + + } // get + + /** + * This checks to see if this is an instance or procedure calls + * and then sets the correct variable based on that + */ + public static function set($name, $value, $clobber = 0) { + + if (isset($this)) { + if (isset($this->_local[$name]) && !$clobber) { + Error::add('Config Instance',"Trying to clobber '$name' without setting clobber"); + return; + } + else { + $this->_local[$name] = $value; + } + } // if object + else { + if (isset(self::$_global[$name]) && !$clobber) { + Error::add('Config Global',"Trying to clobber'$name' without setting clobber"); + return; + } + else { + self::$_global[$name] = $value; + } + } // else not object, procedure call + + } // set + + /** + * This is the same as the set function except it takes an array as input + */ + + public static function set_by_array($array, $clobber = 0) { + + if (isset($this)) { + foreach ($array as $name => $value) { + $this->set($name, $value, $clobber); + } // end foreach + } // if this is an object + else { + foreach ($array as $name => $value) { + self::set($name,$value,$clobber); + } + } // end if procedural call + + } // set_by_array + +} // end Config class +?> diff --git a/lib/class/dba.class.php b/lib/class/dba.class.php new file mode 100644 index 00000000..97810613 --- /dev/null +++ b/lib/class/dba.class.php @@ -0,0 +1,168 @@ +get($database))) { + $dbh = self::_connect($database); + self::$config->set($database,$dbh,1); + return $dbh; + } + else { + return self::$config->get($database); + } + + + } // dbh + + /** + * insert_id + * This emulates the mysql_insert_id function, it takes + * an optional database target + */ + public static function insert_id() { + + $id = mysql_insert_id(self::dbh()); + return $id; + + } // insert_id + + /** + * auto_init + * This is the auto init function it sets up the config class + * and also sets the default database + */ + public static function auto_init() { + + self::$_default_db = Config::get('mysql_database'); + self::$config = new Config(); + + return true; + + } // auto_init + +} // dba class + +?> -- cgit