X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fschema.php;h=e5def514e31ddbc227ecb2a6afaec272c9c5d2dc;hb=7436e5d13e6bc242a93e2f6dc561c59f88de60ee;hp=137b814e0269ed727978e11e55ce25cca763a199;hpb=3c61f45de1226b22eeb83bd1f6db01984f953737;p=quix0rs-gnu-social.git diff --git a/lib/schema.php b/lib/schema.php index 137b814e02..e5def514e3 100644 --- a/lib/schema.php +++ b/lib/schema.php @@ -47,40 +47,47 @@ if (!defined('STATUSNET')) { class Schema { - static $_single = null; + static $_static = null; protected $conn = null; /** * Constructor. Only run once for singleton object. */ - protected function __construct() + protected function __construct($conn = null) { - // XXX: there should be an easier way to do this. - $user = new User(); - - $this->conn = $user->getDatabaseConnection(); - - $user->free(); + if (is_null($conn)) { + // XXX: there should be an easier way to do this. + $user = new User(); + $conn = $user->getDatabaseConnection(); + $user->free(); + unset($user); + } - unset($user); + $this->conn = $conn; } /** * Main public entry point. Use this to get - * the singleton object. + * the schema object. * - * @return Schema the (single) Schema object + * @return Schema the Schema object for the connection */ - static function get() + static function get($conn = null) { + if (is_null($conn)) { + $key = 'default'; + } else { + $key = md5(serialize($conn->dsn)); + } + $type = common_config('db', 'type'); - if (empty(self::$_single)) { + if (empty(self::$_static[$key])) { $schemaClass = ucfirst($type).'Schema'; - self::$_single = new $schemaClass(); + self::$_static[$key] = new $schemaClass($conn); } - return self::$_single; + return self::$_static[$key]; } /** @@ -485,3 +492,9 @@ class Schema return $sql; } } + +class SchemaTableMissingException extends Exception +{ + // no-op +} +