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
2012-04-02 09:47:13 -04:00
new DB_Reg($key);
2012-03-07 18:57:52 -05:00
}
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
*/
2012-04-02 08:43:27 -04:00
public static function get_connections()
2012-03-30 18:40:06 -04:00
{
return array_keys(self::$instance);
}
}
// End of dbreg.php