--- FreeBSD/tinderbox/webui/core/TinderboxDS.php 2007/11/13 07:52:29 1.1.1.1.2.2 +++ FreeBSD/tinderbox/webui/core/TinderboxDS.php 2007/11/15 15:31:35 1.1.1.1.2.3 @@ -24,15 +24,14 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# $Paefchen: FreeBSD/tinderbox/webui/core/TinderboxDS.php,v 1.1.1.1.2.1 2007/11/09 22:47:22 as Exp $ +# $Paefchen: FreeBSD/tinderbox/webui/core/TinderboxDS.php,v 1.1.1.1.2.2 2007/11/13 07:52:29 as Exp $ # $MCom: portstools/tinderbox/webui/core/TinderboxDS.php,v 1.36 2007/10/13 02:28:47 ade Exp $ # require_once 'DB.php'; -require_once 'inc_ds.php'; -require_once 'inc_tinderbox.php'; class TinderboxDS { + static private $instance = false; private $objectMap = array( 'Build' => 'builds', 'BuildPortsQueue' => 'build_ports_queue', @@ -42,11 +41,11 @@ class TinderboxDS { 'PortsTree' => 'ports_trees', 'PortFailReason' => 'port_fail_reasons', 'User' => 'users'); - public $db; + private $db; private $error = null; - public $packageSuffixCache; /* in use by getPackageSuffix() */ + private $packageSuffixCache; /* in use by getPackageSuffix() */ - public function __construct() { + private function __construct() { global $DB_HOST, $DB_DRIVER, $DB_NAME, $DB_USER, $DB_PASS; # XXX: backwards compatibility @@ -58,15 +57,21 @@ class TinderboxDS { $this->db = DB::connect($dsn); if (DB::isError($this->db)) - die (sprintf("Tinderbox DS: Unable to initialize datastore: %s\n", - $this->db->getMessage())); + die (sprintf("Error => %s: Unable to initialize datastore: %s\n", + __CLASS__, $this->db->getMessage())); $this->db->setFetchMode(DB_FETCHMODE_ASSOC); $this->db->setOption('persistent', true); } - private function __destruct() { - $this->db->disconnect(); + static public function instance() { + if (! self::$instance) + self::$instance = new TinderboxDS; + return self::$instance; + } + + public function __destruct() { + @$this->db->disconnect(); $this->error = null; }