revamp service factory
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@393 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
parent
3350658545
commit
91eb43bec6
4 changed files with 111 additions and 33 deletions
1
data/.gitignore
vendored
Normal file
1
data/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
config.php
|
|
@ -1,6 +1,12 @@
|
||||||
Upgrading SemanticScuttle from a previous version
|
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
|
From version 0.93 to 0.94
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
|
|
|
@ -3,42 +3,112 @@
|
||||||
|
|
||||||
class SemanticScuttle_Service_Factory
|
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();
|
||||||
|
|
||||||
public function getServiceInstance($name, $servicedir = null)
|
/**
|
||||||
|
* 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)
|
||||||
{
|
{
|
||||||
global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype;
|
self::loadDb();
|
||||||
static $instances = array();
|
self::loadService($name);
|
||||||
static $db;
|
return self::$instances[$name];
|
||||||
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);
|
* Loads service with the given name into
|
||||||
}
|
* self::$instances[$name].
|
||||||
$db->sql_query("SET NAMES UTF8");
|
*
|
||||||
}
|
* @param string $name Service name (i.e. 'Bookmark')
|
||||||
|
*
|
||||||
if (!isset($instances[$name])) {
|
* @return void
|
||||||
if (isset($serviceoverrules[$name])) {
|
*/
|
||||||
$name = $serviceoverrules[$name];
|
protected static function loadService($name)
|
||||||
}
|
{
|
||||||
if (!class_exists($name)) {
|
if (isset(self::$instances[$name])) {
|
||||||
if (!isset($servicedir)) {
|
return;
|
||||||
$servicedir = 'SemanticScuttle/Service/';
|
}
|
||||||
}
|
|
||||||
|
if (isset(self::$serviceoverrides[$name])) {
|
||||||
require_once $servicedir . $name . '.php';
|
$class = self::$serviceoverrides[$name];
|
||||||
}
|
} else {
|
||||||
$instances[$name] = call_user_func(
|
$class = 'SemanticScuttle_Service_' . $name;
|
||||||
array('SemanticScuttle_Service_' . $name, 'getInstance'),
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads self::$db if it is not loaded already.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function loadDb()
|
||||||
|
{
|
||||||
|
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
|
$db
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return $instances[$name];
|
$db->sql_query('SET NAMES UTF8');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -173,6 +173,7 @@ class SemanticScuttle_Service_Vote extends SemanticScuttle_Service
|
||||||
public function rewriteVotings()
|
public function rewriteVotings()
|
||||||
{
|
{
|
||||||
//FIXME
|
//FIXME
|
||||||
|
//SELECT bid, SUM( vote ) FROM sc_votes GROUP BY bid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue