1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
<?php
/**
* Kronolith_Storage:: defines an API for storing free/busy information.
*
* $Horde: kronolith/lib/Storage.php,v 1.2.10.3 2007/12/20 14:12:33 jan Exp $
*
* @author Mike Cochrane <mike@graftonhall.co.nz>
* @package Kronolith
*/
class Kronolith_Storage {
/**
* String containing the current username.
*
* @var string
*/
var $_user = '';
/**
* Attempts to return a concrete Kronolith_Storage instance based on $driver.
*
* @param string $driver The type of concrete Kronolith_Storage subclass
* to return. The is based on the storage
* driver ($driver). The code is dynamically
* included.
*
* @param string $user The name of the user who owns the free/busy
* information
*
* @param array $params (optional) A hash containing any additional
* configuration or connection parameters a
* subclass might need.
*
* @return mixed The newly created concrete Kronolith_Storage instance, or
* false on an error.
*/
function &factory($user = null, $driver = null, $params = null)
{
if (is_null($user)) {
$user = Auth::getAuth();
}
if (is_null($driver)) {
$driver = $GLOBALS['conf']['storage']['driver'];
}
$driver = basename($driver);
if (is_null($params)) {
$params = Horde::getDriverConfig('storage', $driver);
}
require_once dirname(__FILE__) . '/Storage/' . $driver . '.php';
$class = 'Kronolith_Storage_' . $driver;
if (class_exists($class)) {
$driver = &new $class($user, $params);
} else {
$driver = PEAR::raiseError(sprintf(_("Unable to load the definition of %s."), $class));
return $driver;
}
$result = $driver->initialize();
if (is_a($result, 'PEAR_Error')) {
$driver = &new Kronolith_Storage($params);
}
return $driver;
}
/**
* Attempts to return a reference to a concrete Kronolith_Storage instance
* based on $driver. It will only create a new instance if no
* Kronolith_Storage instance with the same parameters currently exists.
*
* This should be used if multiple storage sources are required.
*
* This method must be invoked as: $var = &Kronolith_Storage::singleton()
*
* @param string $driver The type of concrete Kronolith_Storage subclass
* to return. The is based on the storage
* driver ($driver). The code is dynamically
* included.
*
* @param string $user The name of the user who owns the free/busy
* information
*
* @param array $params (optional) A hash containing any additional
* configuration or connection parameters a
* subclass might need.
*
* @return mixed The created concrete Kronolith_Storage instance, or false
* on error.
*/
function &singleton($user = null, $driver = null, $params = null)
{
static $instances;
if (is_null($user)) {
$user = Auth::getAuth();
}
if (is_null($driver)) {
$driver = $GLOBALS['conf']['storage']['driver'];
}
if (is_null($params)) {
$params = Horde::getDriverConfig('storage', $driver);
}
if (!isset($instances)) {
$instances = array();
}
$signature = serialize(array($user, $driver, $params));
if (!isset($instances[$signature])) {
$instances[$signature] = &Kronolith_Storage::factory($user, $driver, $params);
}
return $instances[$signature];
}
/**
* Stub to initiate a driver.
*/
function initialize()
{
return true;
}
/**
* Stub to be overridden in the child class.
*/
function search()
{
return PEAR::raiseError(_("Searching free/busy is not available."));
}
/**
* Stub to be overridden in the child class.
*/
function store()
{
return PEAR::raiseError(_("Storing free/busy is not available."));
}
}
|