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

Benjamin Mako Hill || Want to submit a patch?