]> projects.mako.cc - scuttle/blob - services/servicefactory.php
updated gettext based on new strings
[scuttle] / services / servicefactory.php
1 <?php
2 class ServiceFactory {
3     function ServiceFactory(&$db, $serviceoverrules = array()) {
4     }
5
6     function &getServiceInstance($name, $servicedir = NULL) {
7         global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype;
8         static $instances = array();
9         static $db;
10         if (!isset($db)) {
11             require_once dirname(__FILE__) .'/../includes/db/'. $dbtype .'.php';
12             $db = new sql_db();
13             $db->sql_connect($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist);
14             if(!$db->db_connect_id) {
15                 message_die(CRITICAL_ERROR, "Could not connect to the database", $db);
16             }
17         }
18         if (!isset($instances[$name])) {
19             if (isset($serviceoverrules[$name])) {
20                 $name = $serviceoverrules[$name];
21             }
22             if (!class_exists($name)) {
23                 if (!isset($servicedir)) {
24                     $servicedir = dirname(__FILE__) .'/';
25                 }
26                 require_once $servicedir . strtolower($name) .'.php';
27             }
28             $instances[$name] = call_user_func_array(array($name, 'getInstance'), array(&$db));
29         }
30         return $instances[$name];
31     }
32 }

Benjamin Mako Hill || Want to submit a patch?