From: Ben Klang Date: Sun, 3 Oct 2010 01:53:00 +0000 (-0400) Subject: Rework Factory mechanism for Horde_Lock based on a *lot* of discussion X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=3800bfa6d7e75c1de8d28fb56f50809216e25f7c;p=horde.git Rework Factory mechanism for Horde_Lock based on a *lot* of discussion --- diff --git a/framework/Core/lib/Horde/Core/Binder/Lock.php b/framework/Core/lib/Horde/Core/Binder/Lock.php deleted file mode 100644 index 3fad1b282..000000000 --- a/framework/Core/lib/Horde/Core/Binder/Lock.php +++ /dev/null @@ -1,33 +0,0 @@ -getInstance('Horde_Log_Logger'); - - if (strcasecmp($driver, 'Sql') === 0) { - $params['db'] = $injector->getInstance('Horde_Db')->getDb('horde', 'lock'); - } - - return Horde_Lock::factory($driver, $params); - } - - public function equals(Horde_Injector_Binder $binder) - { - return false; - } - -} diff --git a/framework/Core/lib/Horde/Core/Factory/Lock.php b/framework/Core/lib/Horde/Core/Factory/Lock.php new file mode 100644 index 000000000..d53b1ccf1 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Factory/Lock.php @@ -0,0 +1,45 @@ + + * + * @category Horde + * @package Core + */ + +class Horde_Core_Factory_Lock extends Horde_Core_Factory +{ + /** + * Attempts to return a concrete instance based on the configured driver. + * + * @return Horde_Lock The newly created concrete instance. + * @throws Horde_Lock_Exception + */ + public function create(Horde_Injector $injector) + { + $driver = empty($GLOBALS['conf']['lock']['driver']) + ? 'Null' + : $GLOBALS['conf']['lock']['driver']; + + if (strcasecmp($driver, 'None') === 0) { + $driver = 'Null'; + } + + $params = Horde::getDriverConfig('lock', $driver); + $params['logger'] = $injector->getInstance('Horde_Log_Logger'); + + if (strcasecmp($driver, 'Sql') === 0) { + $params['db'] = $injector->getInstance('Horde_Db')->getDb('horde', 'lock'); + } + + $driver = Horde_String::ucfirst(basename($driver)); + $class = __CLASS__ . '_' . $driver; + + if (class_exists($class)) { + return new $class($params); + } + + throw new Horde_Lock_Exception('Horde_Lock driver (' . $class . ') not found'); + } +} \ No newline at end of file diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index b814d5029..75506eecf 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -278,7 +278,6 @@ class Horde_Registry 'Horde_History' => 'Horde_Core_Binder_History', 'Horde_Http_Client' => 'Horde_Core_Binder_HttpClient', 'Horde_Ldap' => 'Horde_Core_Binder_Ldap', - 'Horde_Lock' => 'Horde_Core_Binder_Lock', 'Horde_Log_Logger' => 'Horde_Core_Binder_Logger', 'Horde_LoginTasks' => 'Horde_Core_Binder_LoginTasks', 'Horde_Mail' => 'Horde_Core_Binder_Mail', @@ -333,6 +332,10 @@ class Horde_Registry 'Horde_Core_Factory_KolabStorage', 'getStorage', ), + 'Horde_Lock' => array( + 'Horde_Core_Factory_Lock', + 'create', + ), 'Horde_View' => array( 'Horde_Core_Factory_View', 'create', diff --git a/framework/Core/package.xml b/framework/Core/package.xml index 7c4380abf..9eb8aaad0 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -23,8 +23,8 @@ Application Framework. slusarz@horde.org yes - 2010-07-01 - + 2010-10-02 + 0.1.0 0.1.0 @@ -34,7 +34,8 @@ Application Framework. beta LGPL - * Add Horde::addInlineJsVars(). + +* Add Horde::addInlineJsVars(). * Remove Horde::nocacheUrl() and Horde::url() (Ticket #9160). * Absorb horde/Ui package. * Absorb horde/Ajax package. @@ -67,8 +68,8 @@ Application Framework. - + @@ -79,11 +80,11 @@ Application Framework. - - + + @@ -124,10 +125,10 @@ Application Framework. - + @@ -165,6 +166,7 @@ Application Framework. + @@ -203,7 +205,6 @@ Application Framework. - @@ -232,6 +233,7 @@ Application Framework. + @@ -413,11 +415,12 @@ Application Framework. + + + - - @@ -445,10 +448,10 @@ Application Framework. - + @@ -459,8 +462,8 @@ Application Framework. - + @@ -482,6 +485,7 @@ Application Framework. + @@ -501,7 +505,6 @@ Application Framework. - @@ -509,8 +512,6 @@ Application Framework. - - @@ -520,6 +521,8 @@ Application Framework. + + @@ -528,6 +531,13 @@ Application Framework. + + + + + + + @@ -571,10 +581,14 @@ Initial packaging beta beta - 2010-07-01 + 2010-10-02 LGPL -* Import application auth driver from horde/Auth. +* Add Horde::addInlineJsVars(). + * Remove Horde::nocacheUrl() and Horde::url() (Ticket #9160). + * Absorb horde/Ui package. + * Absorb horde/Ajax package. + * Import application auth driver from horde/Auth. * Import signup code from horde/Auth. * Import Horde backend driver from horde/LoginTasks. * Import perms UI handling class from horde/Perms. diff --git a/framework/Lock/lib/Horde/Lock.php b/framework/Lock/lib/Horde/Lock.php index 92219c8ae..dcc0b19a3 100644 --- a/framework/Lock/lib/Horde/Lock.php +++ b/framework/Lock/lib/Horde/Lock.php @@ -3,12 +3,12 @@ * The Horde_Lock class provides an API to create, store, check and expire locks * based on a given resource URI. * - * Copyright 2008-2010 The Horde Project (http://www.horde.org/) + * Copyright 2008-2010 Horde LLC (http://www.horde.org/) * * 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 + * @author Ben Klang * @category Horde * @package Lock */ @@ -19,27 +19,128 @@ class Horde_Lock const TYPE_SHARED = 2; /** - * Attempts to return a concrete instance based on $driver. + * Driver parameters. * - * @param mixed $driver The type of concrete 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. + * @var array + */ + protected $_params; + + /** + * Logger. * - * @return Horde_Lock_Base The newly created concrete instance. - * @throws Horde_Lock_Exception + * @var Horde_Log_Logger */ - static public function factory($driver, $params = array()) - { - $driver = Horde_String::ucfirst(basename($driver)); - $class = __CLASS__ . '_' . $driver; + protected $_logger; - if (class_exists($class)) { - return new $class($params); + /** + * Constructor. + * + * @param array $params Configuration parameters: + *
+     * 'logger' - (Horde_Log_Logger) A logger instance.
+     * 
+ */ + public function __construct($params = array()) + { + if (!empty($params['logger'])) { + $this->_logger = $params['logger']; + unset($params['logger']); } - throw new Horde_Lock_Exception('Horde_Lock driver (' . $class . ') not found'); + $this->_params = $params; } + /** + * 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 + */ + abstract public function getLockInfo($lockid); + + /** + * 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 + */ + abstract public function getLocks($scope = null, $principal = null, + $type = null); + + /** + * 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 + */ + abstract public function resetLock($lockid, $extend); + + /** + * 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 + */ + abstract public function setLock($requestor, $scope, $principal, + $lifetime = 1, + $exclusive = Horde_Lock::TYPE_SHARED); + + /** + * 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 + */ + abstract public function clearLock($lockid); } diff --git a/framework/Lock/lib/Horde/Lock/Base.php b/framework/Lock/lib/Horde/Lock/Base.php deleted file mode 100644 index b9b3e5acd..000000000 --- a/framework/Lock/lib/Horde/Lock/Base.php +++ /dev/null @@ -1,142 +0,0 @@ - - * @category Horde - * @package Lock - */ -abstract class Horde_Lock_Base -{ - /** - * Driver parameters. - * - * @var array - */ - protected $_params; - - /** - * Logger. - * - * @var Horde_Log_Logger - */ - protected $_logger; - - /** - * Constructor. - * - * @param array $params Configuration parameters: - *
-     * 'logger' - (Horde_Log_Logger) A logger instance.
-     * 
- */ - public function __construct($params = array()) - { - if (!empty($params['logger'])) { - $this->_logger = $params['logger']; - unset($params['logger']); - } - - $this->_params = $params; - } - - /** - * 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 - */ - abstract public function getLockInfo($lockid); - - /** - * 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 - */ - abstract public function getLocks($scope = null, $principal = null, - $type = null); - - /** - * 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 - */ - abstract public function resetLock($lockid, $extend); - - /** - * 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 - */ - abstract public function setLock($requestor, $scope, $principal, - $lifetime = 1, - $exclusive = Horde_Lock::TYPE_SHARED); - - /** - * 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 - */ - abstract public function clearLock($lockid); - -} diff --git a/framework/Lock/lib/Horde/Lock/Null.php b/framework/Lock/lib/Horde/Lock/Null.php index b180a848e..a49e3c10e 100644 --- a/framework/Lock/lib/Horde/Lock/Null.php +++ b/framework/Lock/lib/Horde/Lock/Null.php @@ -11,7 +11,7 @@ * @category Horde * @package Lock */ -class Horde_Lock_Null extends Horde_Lock_Base +class Horde_Lock_Null extends Horde_Lock { /** * Return an array of information about the requested lock. diff --git a/framework/Lock/lib/Horde/Lock/Sql.php b/framework/Lock/lib/Horde/Lock/Sql.php index d874e8b05..6e9479f75 100644 --- a/framework/Lock/lib/Horde/Lock/Sql.php +++ b/framework/Lock/lib/Horde/Lock/Sql.php @@ -19,16 +19,16 @@ * ); * * - * Copyright 2008-2010 The Horde Project (http://www.horde.org/) + * Copyright 2008-2010 Horde LLC (http://www.horde.org/) * * 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 + * @author Ben Klang * @category Horde * @package Lock */ -class Horde_Lock_Sql extends Horde_Lock_Base +class Horde_Lock_Sql extends Horde_Lock { /** * Handle for the current database connection. diff --git a/framework/Lock/package.xml b/framework/Lock/package.xml index 0b3f464e9..acad2fab5 100644 --- a/framework/Lock/package.xml +++ b/framework/Lock/package.xml @@ -1,21 +1,17 @@ - + Lock pear.horde.org Horde Resource Locking System - The Lock:: class provides the Horde resource locking system. - + The Lock:: class provides the Horde resource locking system. Ben Klang bklang ben@alkaloid.net yes - 2008-05-05 - + 2010-10-02 + 0.0.1 0.0.1 @@ -25,23 +21,23 @@ http://pear.php.net/dtd/package-2.0.xsd"> alpha LGPL - * Add Null driver. + +* Add Null driver. * Initial release - + - - + - - - +
+
+
@@ -80,11 +76,28 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - + + + + + + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + 2010-10-02 + LGPL + +* Add Null driver. +* Initial release + + +