]> projects.mako.cc - scuttle/blobdiff - services/servicefactory.php
updated readme with information on a series of bugs I know exist
[scuttle] / services / servicefactory.php
index ba2d6d7910a1ecc459d1ac09008847b0ba831f16..7186b059ab89f7ad971da7d3b060358adffdb667 100644 (file)
@@ -1,20 +1,21 @@
 <?php
 class ServiceFactory {
 <?php
 class ServiceFactory {
-    function ServiceFactory(&$db, $serviceoverrules = array()) {    
+    function ServiceFactory() {
     }
     }
-  
+
     function &getServiceInstance($name, $servicedir = NULL) {
         global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype;
     function &getServiceInstance($name, $servicedir = NULL) {
         global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype;
-        static $instances = array();
         static $db;
         if (!isset($db)) {
         static $db;
         if (!isset($db)) {
-            require_once(dirname(__FILE__) .'/../includes/db/'. $dbtype .'.php');
+            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);
             }
         }
             $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);
             }
         }
+
+        static $instances = array();
         if (!isset($instances[$name])) {
             if (isset($serviceoverrules[$name])) {
                 $name = $serviceoverrules[$name];
         if (!isset($instances[$name])) {
             if (isset($serviceoverrules[$name])) {
                 $name = $serviceoverrules[$name];
@@ -23,11 +24,10 @@ class ServiceFactory {
                 if (!isset($servicedir)) {
                     $servicedir = dirname(__FILE__) .'/';
                 }
                 if (!isset($servicedir)) {
                     $servicedir = dirname(__FILE__) .'/';
                 }
-                require_once($servicedir . strtolower($name) . '.php');
+                require_once $servicedir . strtolower($name) .'.php';
             }
             }
-            $instances[$name] = call_user_func(array($name, 'getInstance'), $db);
-        }        
+            $instances[$name] = (new $name($db))->getInstance($db);
+        }
         return $instances[$name];
     }
 }
         return $instances[$name];
     }
 }
-?>
\ No newline at end of file

Benjamin Mako Hill || Want to submit a patch?