2007-12-12 16:29:16 +00:00
|
|
|
<?php
|
2008-11-21 11:22:40 +00:00
|
|
|
/* Connect to the database and build services */
|
2008-11-21 11:02:01 +00:00
|
|
|
|
2007-12-12 16:29:16 +00:00
|
|
|
class ServiceFactory {
|
2008-11-21 11:22:40 +00:00
|
|
|
function ServiceFactory(&$db, $serviceoverrules = array()) {
|
|
|
|
}
|
|
|
|
|
|
|
|
function &getServiceInstance($name, $servicedir = NULL) {
|
|
|
|
global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype;
|
|
|
|
static $instances = array();
|
|
|
|
static $db;
|
|
|
|
if (!isset($db)) {
|
|
|
|
require_once(dirname(__FILE__) .'/../includes/db/'. $dbtype .'.php');
|
|
|
|
$db = new sql_db();
|
|
|
|
$db->sql_connect($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist);
|
|
|
|
if(!$db->db_connect_id) {
|
|
|
|
message_die(CRITICAL_ERROR, "Could not connect to the database", $db);
|
|
|
|
}
|
2009-02-05 15:22:30 +00:00
|
|
|
$db->sql_query("SET NAMES UTF8");
|
2008-12-18 11:03:40 +00:00
|
|
|
}
|
|
|
|
|
2008-11-21 11:22:40 +00:00
|
|
|
if (!isset($instances[$name])) {
|
|
|
|
if (isset($serviceoverrules[$name])) {
|
|
|
|
$name = $serviceoverrules[$name];
|
|
|
|
}
|
|
|
|
if (!class_exists($name)) {
|
|
|
|
if (!isset($servicedir)) {
|
|
|
|
$servicedir = dirname(__FILE__) .'/';
|
|
|
|
}
|
2008-12-18 11:03:40 +00:00
|
|
|
|
2008-11-21 11:22:40 +00:00
|
|
|
require_once($servicedir . strtolower($name) . '.php');
|
|
|
|
}
|
|
|
|
$instances[$name] = call_user_func(array($name, 'getInstance'), $db);
|
|
|
|
}
|
|
|
|
return $instances[$name];
|
|
|
|
}
|
2007-12-12 16:29:16 +00:00
|
|
|
}
|
2008-01-09 15:51:35 +00:00
|
|
|
?>
|