]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
revamp service factory
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Fri, 23 Oct 2009 16:54:51 +0000 (16:54 +0000)
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Fri, 23 Oct 2009 16:54:51 +0000 (16:54 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@393 b3834d28-1941-0410-a4f8-b48e95affb8f

data/.gitignore [new file with mode: 0644]
doc/UPGRADE.txt
src/SemanticScuttle/Service/Factory.php
src/SemanticScuttle/Service/Vote.php

diff --git a/data/.gitignore b/data/.gitignore
new file mode 100644 (file)
index 0000000..4f4773f
--- /dev/null
@@ -0,0 +1 @@
+config.php
index cd8097f3468d8f052caf10200593a822943ab755..7352b12d8e0c868fbca8b130f2123343d5fdf32a 100644 (file)
@@ -1,6 +1,12 @@
 Upgrading SemanticScuttle from a previous version
 =================================================
 
+From versin 0.94 to 0.10.0
+--------------------------
+- ALTER TABLE `sc_bookmarks` ADD `bVoting` INT NOT NULL ;
+- Add the new votes database table. See data/tables.sql.
+
+
 From version 0.93 to 0.94
 -------------------------
 
index b4ba28e11147158b97580f19ff9569986f9d8c53..b6f79d5298d75d4f246a8204b46433b522facf9c 100644 (file)
 
 class SemanticScuttle_Service_Factory
 {
-       public function __construct($db, $serviceoverrules = array())
+    /**
+     * Array of service instances.
+     * Key is service name (i.e. "Bookmark")
+     *
+     * @var array
+     */
+    protected static $instances = array();
+
+    /**
+     * Database connection
+     *
+     * @var sql_qb
+     */
+    protected static $db = null;
+
+    /**
+     * Array of service names -> new service class
+     * in case you want to overwrite the services.
+     *
+     * Key is the old service name (i.e. "Bookmark"),
+     * value the new class name, e.g.
+     * "My_Cool_Own_BookmarkService"
+     *
+     * @var array
+     */
+    protected static $serviceoverrides = array();
+
+
+
+    /**
+     * Returns the service for the given name.
+     *
+     * @param string $name Service name (i.e. "Bookmark")
+     *
+     * @return SemanticScuttle_Service Service object
+     */
+    public static function getServiceInstance($name)
+    {
+        self::loadDb();
+        self::loadService($name);
+        return self::$instances[$name];
+    }
+
+
+
+    /**
+     * Loads service with the given name into
+     * self::$instances[$name].
+     *
+     * @param string $name Service name (i.e. 'Bookmark')
+     *
+     * @return void
+     */
+    protected static function loadService($name)
     {
-       }
+        if (isset(self::$instances[$name])) {
+            return;
+        }
+
+        if (isset(self::$serviceoverrides[$name])) {
+            $class = self::$serviceoverrides[$name];
+        } else {
+            $class = 'SemanticScuttle_Service_' . $name;
+        }
+
+        if (!class_exists($class)) {
+            //PEAR classname to filename rule
+            $file = str_replace('_', '/', $class) . '.php';
+            require_once $file;
+        }
+
+        self::$instances[$name] = call_user_func(
+            array($class, 'getInstance'),
+            self::$db
+        );
+    }
 
-       public function getServiceInstance($name, $servicedir = null)
+
+
+    /**
+     * Loads self::$db if it is not loaded already.
+     *
+     * @return void
+     */
+    protected static function loadDb()
     {
-               global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype;
-               static $instances = array();
-               static $db;
-               if (!isset($db)) {
-                       require_once 'SemanticScuttle/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->sql_query("SET NAMES UTF8"); 
-               }               
-               
-               if (!isset($instances[$name])) {
-                       if (isset($serviceoverrules[$name])) {
-                               $name = $serviceoverrules[$name];
-                       }
-                       if (!class_exists($name)) {
-                               if (!isset($servicedir)) {
-                                       $servicedir = 'SemanticScuttle/Service/';
-                               }
-                                                               
-                               require_once $servicedir . $name . '.php';
-                       }
-                       $instances[$name] = call_user_func(
-                array('SemanticScuttle_Service_' . $name, 'getInstance'),
+        global $dbhost, $dbuser, $dbpass, $dbname, 
+            $dbport, $dbpersist, $dbtype;
+
+        if (self::$db !== null) {
+            return;
+        }
+        require_once 'SemanticScuttle/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
             );
-               }
-               return $instances[$name];
-       }
+        }
+        $db->sql_query('SET NAMES UTF8');
+    }
+
 }
 ?>
index e348512940215604716eea1411f253f4d1c1e972..3c4a14425abe60e36a2604e9b9d9f9d9870f758e 100644 (file)
@@ -173,6 +173,7 @@ class SemanticScuttle_Service_Vote extends SemanticScuttle_Service
     public function rewriteVotings()
     {
         //FIXME
+        //SELECT bid, SUM( vote ) FROM sc_votes GROUP BY bid
     }