$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();
$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);
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)
* 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 <ben@alkaloid.net>
- * @package Horde_Lock
+ * @author Ben Klang <ben@alkaloid.net>
+ * @category Horde
+ * @package Lock
*/
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.
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];
- }
-
}
* 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 <ben@alkaloid.net>
- * @package Horde_Lock
+ * @author Ben Klang <ben@alkaloid.net>
+ * @category Horde
+ * @package Lock
*/
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);
* @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);
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
- * @package Horde_Lock
+ * @package Lock
*/
class Horde_Lock_Exception extends Horde_Exception_Prior {}
--- /dev/null
+<?php
+/**
+ * A null driver for Horde_Lock.
+ *
+ * Copyright 2010 The Horde Project (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 Michael Slusarz <slusarz@curecanti.org>
+ * @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;
+ }
+
+}
* 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 <ben@alkaloid.net>
- * @package Horde_Lock
+ * @author Ben Klang <ben@alkaloid.net>
+ * @category Horde
+ * @package Lock
*/
class Horde_Lock_Sql extends Horde_Lock_Driver
{
if ($this->_logger) {
$this->_logger->log(sprintf('Lock %s reset successfully.', $lockid), 'DEBUG');
}
+
return true;
}
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']),
<api>alpha</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Initial release
+ <notes>* Add Null driver.
+* Initial release
</notes>
<contents>
<dir name="/">
<dir name="Lock">
<file name="Driver.php" role="php" />
<file name="Exception.php" role="php" />
+ <file name="Null.php" role="php" />
<file name="Sql.php" role="php" />
</dir> <!-- /lib/Horde/Lock -->
<file name="Lock.php" role="php" />
<min>1.7.0</min>
</pearinstaller>
<package>
- <name>Core</name>
- <channel>pear.horde.org</channel>
- </package>
- <package>
<name>Support</name>
<channel>pear.horde.org</channel>
</package>
<filelist>
<install name="lib/Horde/Lock/Driver.php" as="Horde/Lock/Driver.php" />
<install name="lib/Horde/Lock/Exception.php" as="Horde/Lock/Exception.php" />
+ <install name="lib/Horde/Lock/Null.php" as="Horde/Lock/Null.php" />
<install name="lib/Horde/Lock/Sql.php" as="Horde/Lock/Sql.php" />
<install name="lib/Horde/Lock.php" as="Horde/Lock.php" />
</filelist>
<configsection name="lock">
<configheader>Lock System Settings</configheader>
<configswitch name="driver" desc="If you want to enable resource locking
- you must choose a driver here.">Sql
- <case name="none" desc="Disable Horde Locks"/>
+ you must choose a driver here.">Null
+ <case name="Null" desc="Disable Horde Locks"/>
<case name="Sql" desc="SQL-based locking">
<configsection name="params">
<configsql switchname="driverconfig">