OpenSQLManager/sys/db/dbreg.php

70 lines
1.5 KiB
PHP
Raw Normal View History

2012-03-07 18:57:52 -05:00
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
2012-03-30 18:40:06 -04:00
* @license http://philsturgeon.co.uk/code/dbad-license
2012-03-07 18:57:52 -05:00
*/
// --------------------------------------------------------------------------
/**
* Connection registry
2012-03-30 18:40:06 -04:00
*
2012-03-07 18:57:52 -05:00
* Decouples the Settings class from the query builder
* and organizes database connections
*/
class DB_Reg {
private static $instance;
/**
* Registry access method
2012-03-30 18:40:06 -04:00
*
2012-03-07 18:57:52 -05:00
* @param string $key
* @return object
*/
public static function &get_db($key)
{
if ( ! isset(self::$instance[$key]))
{
// The constructor sets the instance
new DBReg($key);
}
return self::$instance[$key];
}
// --------------------------------------------------------------------------
/**
* Private constructor
2012-03-30 18:40:06 -04:00
*
2012-03-07 18:57:52 -05:00
* @param string $key
*/
2012-03-30 18:40:06 -04:00
private function __construct($key)
2012-03-07 18:57:52 -05:00
{
// Get the db connection parameters for the current database
$db_params = Settings::get_instance()->get_db($key);
// Set the current key in the registry
self::$instance[$key] = new Query_Builder($db_params);
}
2012-03-30 18:40:06 -04:00
// --------------------------------------------------------------------------
/**
* Return exiting connections
*
* @return array
*/
public function get_connections()
{
return array_keys(self::$instance);
}
}
// End of dbreg.php