This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
OpenSQLManager/sys/common/db_reg.php

92 lines
1.9 KiB
PHP
Raw Normal View History

2012-05-31 09:56:49 -04:00
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @package OpenSQLManager
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
2012-11-27 09:47:27 -05:00
* @license https://timshomepage.net/dbaj.txt
2012-05-31 09:56:49 -04:00
*/
// --------------------------------------------------------------------------
namespace OpenSQLManager;
/**
* Connection registry
*
* Decouples the Settings class from the query builder
* and organizes database connections
*
2012-06-05 16:53:03 -04:00
* @package OpenSQLManager
* @subpackage Common
2012-05-31 09:56:49 -04:00
*/
class DB_Reg {
/**
* Static array of connections
*/
private static $instance=array();
/**
* Registry access method
*
* @param string $key
* @return object
*/
public static function &get_db($key)
{
if ( ! isset(self::$instance[$key]))
{
// The constructor sets the instance
new DB_Reg($key);
}
return self::$instance[$key];
}
// --------------------------------------------------------------------------
/**
* Private constructor
*
* @param string $key
*/
private function __construct($key)
{
// 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);
}
// --------------------------------------------------------------------------
/**
* Return exiting connections
*
* @return array
*/
public static function get_connections()
{
return array_keys(self::$instance);
}
// --------------------------------------------------------------------------
/**
* Remove a database connection
*
* @param string $key
* @return void
*/
public static function remove_db($key)
{
unset(self::$instance[$key]);
}
}
// End of dbreg.php