From: Michael M Slusarz Date: Tue, 11 May 2010 19:42:13 +0000 (-0600) Subject: Add Null Horde_Lock driver X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7994594b3db35ca7478d608131d8faa214900fb5;p=horde.git Add Null Horde_Lock driver --- diff --git a/babel/view.php b/babel/view.php index f73231694..3eb596ce8 100644 --- a/babel/view.php +++ b/babel/view.php @@ -52,10 +52,9 @@ echo $template->fetch(BABEL_TEMPLATES . '/layout.html'); $app = Horde_Util::getFormData('module'); $show = 'edit'; -$vars = &Horde_Variables::getDefaultVariables(); +$vars = Horde_Variables::getDefaultVariables(); if ($app) { - $napp = ($app == 'horde') ? '' : $app; $pofile = HORDE_BASE . '/' . $napp . '/po/' . $lang . '.po'; $po = new File_Gettext_PO(); @@ -65,7 +64,7 @@ if ($app) { $lockscope = sprintf("babel-%s-%s", $app, $lang); // Initialize Horde_Lock class - $locks = Horde_Lock::singleton('Sql', Horde::getDriverConfig('lock', 'Sql')); + $locks = $injector->getInstance('Horde_Lock'); // $curlocks = $locks->getLocks($lockscope); // var_dump($curlocks); diff --git a/framework/Core/lib/Horde/Core/Binder/Lock.php b/framework/Core/lib/Horde/Core/Binder/Lock.php index 7c605f632..bb1e3b9d0 100644 --- a/framework/Core/lib/Horde/Core/Binder/Lock.php +++ b/framework/Core/lib/Horde/Core/Binder/Lock.php @@ -8,15 +8,22 @@ class Horde_Core_Binder_Lock implements Horde_Injector_Binder public function create(Horde_Injector $injector) { if (empty($GLOBALS['conf']['lock']['driver'])) { - $driver = null; + $driver = 'Null'; } else { $driver = $GLOBALS['conf']['lock']['driver']; - $params = Horde::getDriverConfig('lock', $driver); + if (Horde_String::lower($driver) == 'none') { + $driver = 'Null'; + } } + $params = Horde::getDriverConfig('lock', $driver); $params['logger'] = $injector->getInstance('Horde_Log_Logger'); - return Horde_Lock::singleton($driver, $params); + if (Horde_String::lower($driver) == 'sql') { + Horde_Util::assertDriverConfig($params, array('phptype'), 'Lock SQL'); + } + + return Horde_Lock::factory($driver, $params); } public function equals(Horde_Injector_Binder $binder) diff --git a/framework/Lock/lib/Horde/Lock.php b/framework/Lock/lib/Horde/Lock.php index af68992db..fd3588b0d 100644 --- a/framework/Lock/lib/Horde/Lock.php +++ b/framework/Lock/lib/Horde/Lock.php @@ -8,8 +8,9 @@ * See the enclosed file COPYING for license information (LGPL). If you did * not receive this file, see http://opensource.org/licenses/lgpl-license.php. * - * @author Ben Klang - * @package Horde_Lock + * @author Ben Klang + * @category Horde + * @package Lock */ class Horde_Lock { @@ -18,13 +19,6 @@ class Horde_Lock const TYPE_SHARED = 2; /** - * Singleton instances. - * - * @var array - */ - static protected $_instances = array(); - - /** * Attempts to return a concrete instance based on $driver. * * @param mixed $driver The type of concrete subclass to return. @@ -48,33 +42,4 @@ class Horde_Lock throw new Horde_Lock_Exception('Horde_Lock driver (' . $class . ') not found'); } - /** - * Attempts to return a reference to a concrete instance based on - * $driver. It will only create a new instance if no instance - * with the same parameters currently exists. - * - * This should be used if multiple authentication sources (and, thus, - * multiple Horde_Lock instances) are required. - * - * @param string $driver The type of concrete Horde_Lock subclass to - * return. - * This is based on the storage driver ($driver). - * The code is dynamically included. - * @param array $params A hash containing any additional configuration or - * connection parameters a subclass might need. - * - * @return Horde_Lock_Driver The concrete reference. - * @throws Horde_Lock_Exception - */ - static public function singleton($driver, $params = array()) - { - ksort($params); - $signature = hash('md5', serialize(array($driver, $params))); - if (empty(self::$_instances[$signature])) { - self::$_instances[$signature] = self::factory($driver, $params); - } - - return self::$_instances[$signature]; - } - } diff --git a/framework/Lock/lib/Horde/Lock/Driver.php b/framework/Lock/lib/Horde/Lock/Driver.php index 0628092c5..86f219789 100644 --- a/framework/Lock/lib/Horde/Lock/Driver.php +++ b/framework/Lock/lib/Horde/Lock/Driver.php @@ -7,8 +7,9 @@ * See the enclosed file COPYING for license information (LGPL). If you did * not receive this file, see http://opensource.org/licenses/lgpl-license.php. * - * @author Ben Klang - * @package Horde_Lock + * @author Ben Klang + * @category Horde + * @package Lock */ abstract class Horde_Lock_Driver { @@ -80,7 +81,7 @@ abstract class Horde_Lock_Driver * lock. * @param integer $extend Extend lock this many seconds from now. * - * @return boolean TODO + * @return boolean Returns true on success. * @throws Horde_Lock_Exception */ abstract public function resetLock($lockid, $extend); @@ -133,7 +134,7 @@ abstract class Horde_Lock_Driver * @param string $lockid The lock ID as generated by a previous call * to setLock() * - * @return boolean TODO + * @return boolean Returns true on success. * @throws Horde_Lock_Exception */ abstract public function clearLock($lockid); diff --git a/framework/Lock/lib/Horde/Lock/Exception.php b/framework/Lock/lib/Horde/Lock/Exception.php index 6f7a20df5..249c36e82 100644 --- a/framework/Lock/lib/Horde/Lock/Exception.php +++ b/framework/Lock/lib/Horde/Lock/Exception.php @@ -9,6 +9,6 @@ * * @author Michael Slusarz * @category Horde - * @package Horde_Lock + * @package Lock */ class Horde_Lock_Exception extends Horde_Exception_Prior {} diff --git a/framework/Lock/lib/Horde/Lock/Null.php b/framework/Lock/lib/Horde/Lock/Null.php new file mode 100644 index 000000000..d8784d209 --- /dev/null +++ b/framework/Lock/lib/Horde/Lock/Null.php @@ -0,0 +1,123 @@ + + * @category Horde + * @package Lock + */ +class Horde_Lock_Null extends Horde_Lock_Driver +{ + /** + * Return an array of information about the requested lock. + * + * @param string $lockid Lock ID to look up. + * + * @return array Lock information. + * @throws Horde_Lock_Exception + */ + public function getLockInfo($lockid) + { + return array(); + } + + /** + * Return a list of valid locks with the option to limit the results + * by principal, scope and/or type. + * + * @param string $scope The scope of the lock. Typically the name of + * the application requesting the lock or some + * other identifier used to group locks together. + * @param string $principal Principal for which to check for locks + * @param integer $type Only return locks of the given type. + * Defaults to null, or all locks + * + * @return array Array of locks with the ID as the key and the lock details + * as the value. If there are no current locks this will + * return an empty array. + * @throws Horde_Lock_Exception + */ + public function getLocks($scope = null, $principal = null, $type = null) + { + return array(); + } + + /** + * Extend the valid lifetime of a valid lock to now + $extend. + * + * @param string $lockid Lock ID to reset. Must be a valid, non-expired + * lock. + * @param integer $extend Extend lock this many seconds from now. + * + * @return boolean Returns true on success. + * @throws Horde_Lock_Exception + */ + public function resetLock($lockid, $extend) + { + return true; + } + + /** + * Sets a lock on the requested principal and returns the generated lock + * ID. NOTE: No security checks are done in the Horde_Lock API. It is + * expected that the calling application has done all necessary security + * checks before requesting a lock be granted. + * + * @param string $requestor User ID of the lock requestor. + * @param string $scope The scope of the lock. Typically the name of + * the application requesting the lock or some + * other identifier used to group locks + * together. + * @param string $principal A principal on which a lock should be + * granted. The format can be any string but is + * suggested to be in URI form. + * @param integer $lifetime Time (in seconds) for which the lock will be + * considered valid. + * @param string exclusive One of Horde_Lock::TYPE_SHARED or + * Horde_Lock::TYPE_EXCLUSIVE. + * - An exclusive lock will be enforced strictly + * and must be interpreted to mean that the + * resource can not be modified. Only one + * exclusive lock per principal is allowed. + * - A shared lock is one that notifies other + * potential lock requestors that the resource + * is in use. This lock can be overridden + * (cleared or replaced with a subsequent + * call to setLock()) by other users. Multiple + * users may request (and will be granted) a + * shared lock on a given principal. All locks + * will be considered valid until they are + * cleared or expire. + * + * @return mixed A string lock ID. + * @throws Horde_Lock_Exception + */ + public function setLock($requestor, $scope, $principal, $lifetime = 1, + $exclusive = Horde_Lock::TYPE_SHARED) + { + return strval(new Horde_Support_Uuid()); + } + + /** + * Removes a lock given the lock ID. + * NOTE: No security checks are done in the Horde_Lock API. It is + * expected that the calling application has done all necessary security + * checks before requesting a lock be cleared. + * + * @param string $lockid The lock ID as generated by a previous call + * to setLock() + * + * @return boolean Returns true on success. + * @throws Horde_Lock_Exception + */ + public function clearLock($lockid) + { + return true; + } + +} diff --git a/framework/Lock/lib/Horde/Lock/Sql.php b/framework/Lock/lib/Horde/Lock/Sql.php index b3f669fd2..51c626494 100644 --- a/framework/Lock/lib/Horde/Lock/Sql.php +++ b/framework/Lock/lib/Horde/Lock/Sql.php @@ -48,8 +48,9 @@ * See the enclosed file COPYING for license information (LGPL). If you did * not receive this file, see http://opensource.org/licenses/lgpl-license.php. * - * @author Ben Klang - * @package Horde_Lock + * @author Ben Klang + * @category Horde + * @package Lock */ class Horde_Lock_Sql extends Horde_Lock_Driver { @@ -219,6 +220,7 @@ class Horde_Lock_Sql extends Horde_Lock_Driver if ($this->_logger) { $this->_logger->log(sprintf('Lock %s reset successfully.', $lockid), 'DEBUG'); } + return true; } @@ -311,15 +313,6 @@ class Horde_Lock_Sql extends Horde_Lock_Driver return; } - try { - Horde_Util::assertDriverConfig($this->_params, array('phptype'), 'Lock SQL'); - } catch (Horde_Exception $e) { - if ($this->_logger) { - $this->_logger->log($e, 'ERR'); - } - throw new Horde_Lock_Exception($e); - } - $this->_write_db = DB::connect( $this->_params, array('persistent' => !empty($this->_params['persistent']), diff --git a/framework/Lock/package.xml b/framework/Lock/package.xml index 43bc797be..31b14bd3b 100644 --- a/framework/Lock/package.xml +++ b/framework/Lock/package.xml @@ -25,7 +25,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> alpha LGPL - * Initial release + * Add Null driver. +* Initial release @@ -34,6 +35,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -50,10 +52,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> 1.7.0 - Core - pear.horde.org - - Support pear.horde.org @@ -76,6 +74,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/horde/config/conf.xml b/horde/config/conf.xml index f0fd854fd..a17c8381a 100644 --- a/horde/config/conf.xml +++ b/horde/config/conf.xml @@ -1176,8 +1176,8 @@ Lock System Settings Sql - + you must choose a driver here.">Null +