From: Ben Klang Date: Tue, 8 Jun 2010 20:56:32 +0000 (-0400) Subject: Pastie: Fix initialization of SQL driver X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5b2d40fea871fd6ce9b48d177d8c51e1edd20cbf;p=horde.git Pastie: Fix initialization of SQL driver --- diff --git a/pastie/config/conf.xml b/pastie/config/conf.xml index 7442ac496..9727214ff 100644 --- a/pastie/config/conf.xml +++ b/pastie/config/conf.xml @@ -3,14 +3,14 @@ Storage System Settings - sql - - + + sql + - - - - + + + + Text Highlighting Engine diff --git a/pastie/lib/Driver.php b/pastie/lib/Driver.php index e1c23df18..e7994562d 100644 --- a/pastie/lib/Driver.php +++ b/pastie/lib/Driver.php @@ -8,7 +8,7 @@ * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Your Name + * @author Ben Klang * @package Pastie */ class Pastie_Driver @@ -29,14 +29,14 @@ class Pastie_Driver static public function factory($driver = null, $params = null) { if (is_null($driver)) { - $driver = $GLOBALS['conf']['storage']['driver']; + $driver = $GLOBALS['conf']['storage']['params']['driver']; } - $driver = ucfirst(basename($driver)); if (is_null($params)) { $params = Horde::getDriverConfig('storage', $driver); } + $driver = ucfirst(basename($driver)); $class = 'Pastie_Driver_' . $driver; if (class_exists($class)) { return new $class($params); @@ -45,4 +45,48 @@ class Pastie_Driver throw new Horde_Exception('Could not find driver ' . $class); } + /** + * Attempts to return a reference to a concrete Pastie_Driver instance based + * on $driver. + * + * It will only create a new instance if no Pastie_Driver instance with the + * same parameters currently exists. + * + * This should be used if multiple storage sources are required. + * + * This method must be invoked as: $var = &Pastie_Driver::singleton() + * + * @param string $notepad The name of the current notepad. + * + * @param string $driver The type of concrete Pastie_Driver subclass + * to return. The is based on the storage + * driver ($driver). The code is dynamically + * included. + * + * @param array $params (optional) A hash containing any additional + * configuration or connection parameters a + * subclass might need. + * + * @return mixed The created concrete Pastie_Driver instance, or false + * on error. + */ + function &singleton($bin = '', $driver = null, $params = null) + { + static $instances = array(); + if (is_null($driver)) { + $driver = $GLOBALS['conf']['storage']['driver']; + } + + if (is_null($params)) { + $params = Horde::getDriverConfig('storage', $driver); + } + + $signature = serialize(array($notepad, $driver, $params)); + if (!isset($instances[$signature])) { + $instances[$signature] = &Pastie_Driver::factory($notepad, $driver, $params); + } + + return $instances[$signature]; + } + }