forked from jpfuentes2/php-activerecord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,51 @@ | ||
<?php | ||
/** | ||
* @package ActiveRecord | ||
*/ | ||
namespace ActiveRecord; | ||
|
||
/** | ||
* Singleton to manage any and all database connections. | ||
* | ||
* @package ActiveRecord | ||
*/ | ||
class ConnectionManager extends Singleton | ||
{ | ||
/** | ||
* Array of {@link Connection} objects. | ||
* @var array | ||
*/ | ||
static private $connections = array(); | ||
|
||
/** | ||
* If $name is null then the default connection will be returned. | ||
* | ||
* @see Config | ||
* @param string $name Optional name of a connection | ||
* @return Connection | ||
*/ | ||
public static function get_connection($name=null) | ||
{ | ||
$config = Config::instance(); | ||
$name = $name ? $name : $config->get_default_connection(); | ||
|
||
if (!isset(self::$connections[$name]) || !self::$connections[$name]->connection) | ||
self::$connections[$name] = Connection::instance($config->get_connection($name)); | ||
|
||
return self::$connections[$name]; | ||
} | ||
|
||
/** | ||
* Drops the connection from the connection manager. Does not actually close it since there | ||
* is no close method in PDO. | ||
* | ||
* @param string $name Name of the connection to forget about | ||
*/ | ||
public static function drop_connection($name=null) | ||
{ | ||
if (isset(self::$connections[$name])) | ||
unset(self::$connections[$name]); | ||
} | ||
}; | ||
?> | ||
<?php | ||
/** | ||
* @package ActiveRecord | ||
*/ | ||
namespace ActiveRecord; | ||
|
||
/** | ||
* Singleton to manage any and all database connections. | ||
* | ||
* @package ActiveRecord | ||
*/ | ||
class ConnectionManager extends Singleton | ||
{ | ||
/** | ||
* Array of {@link Connection} objects. | ||
* @var array | ||
*/ | ||
static private $connections = array(); | ||
|
||
/** | ||
* If $name is null then the default connection will be returned. | ||
* | ||
* @see Config | ||
* @param string $name Optional name of a connection | ||
* @return Connection | ||
*/ | ||
public static function get_connection($name=null) | ||
{ | ||
$config = Config::instance(); | ||
$name = $name ? $name : $config->get_default_connection(); | ||
|
||
if (!isset(self::$connections[$name]) || !self::$connections[$name]->connection) | ||
self::$connections[$name] = Connection::instance($config->get_connection($name)); | ||
|
||
return self::$connections[$name]; | ||
} | ||
|
||
/** | ||
* Drops the connection from the connection manager. Does not actually close it since there | ||
* is no close method in PDO. | ||
* | ||
* @param string $name Name of the connection to forget about | ||
*/ | ||
public static function drop_connection($name=null) | ||
{ | ||
if (isset(self::$connections[$name])) | ||
unset(self::$connections[$name]); | ||
} | ||
} | ||
|
||
?> |