protected $attributes;
/**
+ * The data cache.
+ *
+ * @var Horde_Cache
+ */
+ protected $cache;
+
+ /**
+ * The log handler.
+ *
+ * @var Horde_Log_Logger
+ */
+ protected $logger;
+
+ /**
* Construct a new Horde_Kolab_Server object.
*
* @param array $params Parameter array.
*/
- public function __construct($params = array())
+ public function __construct(Horde_Kolab_Server_Structure $structure,
+ Horde_Cache $cache = null,
+ Horde_Log_Logger $logger = null,
+ $params = array())
{
- $this->params = $params;
+ $structure->setServer($this);
+ $this->structure = $structure;
+ $this->cache = $cache;
+ $this->logger = $logger;
+ $this->params = $params;
+
+ if (!isset($this->params['cache_lifetime'])) {
+ $this->params['cache_lifetime'] = 300;
+ }
+
if (isset($params['uid'])) {
$this->uid = $params['uid'];
}
- $structure = isset($params['structure']['driver'])
- ? $params['structure']['driver'] : 'kolab';
- $structure_params = isset($params['structure']['params'])
- ? $params['structure']['params'] : array();
-
- $this->structure = &Horde_Kolab_Server_Structure::factory($structure,
- $this,
- $structure_params);
-
// Initialize the search operations supported by this server.
$this->searches = $this->getSearchOperations();
}
* @throws Horde_Kolab_Server_Exception If the requested Horde_Kolab_Server
* subclass could not be found.
*/
- static public function &factory($driver, $params = array())
+ static public function &factory($provider)
{
- $class = 'Horde_Kolab_Server_' . ucfirst(basename($driver));
+ $class = 'Horde_Kolab_Server_' . ucfirst(basename($provider->kolab_server_driver));
if (class_exists($class)) {
- $db = new $class($params);
- return $db;
+ $server = new $class($provider->kolab_server_structure,
+ isset($provider->cache) ? $provider->cache : null,
+ isset($provider->logger) ? $provider->logger : null,
+ $provider->kolab_server_params);
+ return $server;
}
throw new Horde_Kolab_Server_Exception(
'Server type definition "' . $class . '" missing.');
static $instances = array();
+ $provider = new stdClass;
+
$sparam = $params;
$sparam['pass'] = isset($sparam['pass'])
? hash('sha256', $sparam['pass']) : '';
$user_pass = '';
if (!empty($params['driver'])) {
- $driver = $params['driver'];
+ $provider->kolab_server_driver = $params['driver'];
unset($params['driver']);
} else if (isset($conf['kolab']['server']['driver'])) {
- $driver = $conf['kolab']['server']['driver'];
+ $provider->kolab_server_driver = $conf['kolab']['server']['driver'];
if (isset($conf['kolab']['server']['params'])) {
if (!is_array($params)) {
$params = $conf['kolab']['server']['params'];
'The configuration for the Kolab server driver is missing!');
}
+ /* Provide caching */
+ if (!empty($params['cache']['driver']) && class_exists('Horde_Cache')) {
+ $provider->cache = Horde_Cache::singleton($params['cache']['driver'],
+ isset($params['cache']['params'])
+ ? $params['cache']['params'] : null);
+ }
+
+ /* Provide the structure */
+ $structure = isset($params['structure']['driver'])
+ ? $params['structure']['driver'] : 'kolab';
+ $structure_params = isset($params['structure']['params'])
+ ? $params['structure']['params'] : array();
+
+ $provider->kolab_server_structure = &Horde_Kolab_Server_Structure::factory($structure,
+ $structure_params);
+
if (isset($params['user'])) {
- $tmp_server = &Horde_Kolab_Server::factory($driver, $params);
+ $provider->kolab_server_params = $params;
+
+ $tmp_server = &Horde_Kolab_Server::factory($provider);
try {
$uid = $tmp_server->uidForIdOrMail($params['user']);
$params['host'] = $params['host_master'];
}
- $instances[$signature] = &Horde_Kolab_Server::factory($driver,
- $params);
+ $provider->kolab_server_params = $params;
+
+ $instances[$signature] = &Horde_Kolab_Server::factory($provider);
}
return $instances[$signature];
function shutdown()
{
if (isset($this->attributes)) {
- if (!empty($GLOBALS['conf']['kolab']['server']['cache']['driver'])
- && class_exists('Horde_Cache')) {
- $params = isset($GLOBALS['conf']['kolab']['server']['cache']['params'])
- ? $GLOBALS['conf']['kolab']['server']['cache']['params'] : null;
- $cache = Horde_Cache::singleton($GLOBALS['conf']['kolab']['server']['cache']['driver'],
- $params);
+ if (!empty($this->cache)) {
foreach ($this->attributes as $key => $value) {
- $cache->set('attributes_' . $key, @serialize($value));
+ $this->cache->set('attributes_' . $key, @serialize($value));
}
}
}
*/
public function &getAttributes($class)
{
- static $cache = null;
- static $lifetime;
-
if (!isset($this->attributes)) {
- if (!empty($GLOBALS['conf']['kolab']['server']['cache']['driver'])
- && class_exists('Horde_Cache')) {
- $params = isset($GLOBALS['conf']['kolab']['server']['cache']['params'])
- ? $GLOBALS['conf']['kolab']['server']['cache']['params'] : null;
- $cache = Horde_Cache::singleton($GLOBALS['conf']['kolab']['server']['cache']['driver'],
- $params);
+ if (!empty($this->cache)) {
register_shutdown_function(array($this, 'shutdown'));
- $lifetime = isset($GLOBALS['conf']['kolab']['server']['cache']['lifetime'])
- ? $GLOBALS['conf']['kolab']['server']['cache']['lifetime'] : 300;
}
}
if (empty($this->attributes[$class])) {
- if (!empty($cache)) {
- $this->attributes[$class] = @unserialize($cache->get('attributes_' . $class, $lifetime));
+ if (!empty($this->cache)) {
+ $this->attributes[$class] = @unserialize($cache->get('attributes_' . $class,
+ $this->params['cache_lifetime']));
}
if (empty($this->attributes[$class])) {
$classes[] = $childclass;
if ($level == self::MAX_HIERARCHY) {
- Horde::logMessage(sprintf('The maximal level of the object hierarchy has been exceeded for class \"%s\"!',
- $class),
- __FILE__, __LINE__, PEAR_LOG_ERROR);
+ if (!empty($this->logger)) {
+ $logger->err(sprintf('The maximal level of the object hierarchy has been exceeded for class \"%s\"!',
+ $class));
+ }
}
/**
*
* @param array $params Parameter array.
*/
- public function __construct($params = array())
+ public function __construct(Horde_Kolab_Server_Structure $structure,
+ Horde_Cache $cache = null,
+ Horde_Log_Logger $logger = null,
+ $params = array())
{
if (isset($params['file'])) {
$this->_file = $params['file'];
} else {
- $this->_file = Horde::getTempFile('Horde_Kolab_Server', false);
+ throw new Horde_Kolab_Server_Exception('The file based driver requires a \'file\' parameter.');
}
- parent::__construct($params);
+ parent::__construct($structure, $cache, $logger, $params);
}
$this->data = $data;
} else {
$error = error_get_last();
- Horde::logMessage(sprintf('Horde_Kolab_Server_file failed to read the database from %s. Error was: %s',
- $this->_file, $error['message']), __FILE__,
- __LINE__, PEAR_LOG_WARNING);
+ if (!empty($this->logger)) {
+ $this->logger->warn(sprintf('Horde_Kolab_Server_file failed to read the database from %s. Error was: %s',
+ $this->_file, $error['message']));
+ }
$this->data = array();
}
}
$result = @file_put_contents($this->_file, $raw_data);
if ($result === false) {
$error = error_get_last();
- Horde::logMessage(sprintf('Horde_Kolab_Server_file failed to store the database in %s. Error was: %s',
- $this->_file, $error['message']), __FILE__,
- __LINE__, PEAR_LOG_WARNING);
+ if (!empty($this->logger)) {
+ $this->logger->warn(sprintf('Horde_Kolab_Server_file failed to store the database in %s. Error was: %s',
+ $this->_file, $error['message']));
+ }
}
}
*
* @param array $params Parameter array.
*/
- public function __construct($params = array())
+ public function __construct(Horde_Kolab_Server_Structure $structure,
+ Horde_Cache $cache = null,
+ Horde_Log_Logger $logger = null,
+ $params = array())
{
if (!isset($params['charset'])) {
$params['charset'] = 'UTF-8';
$this->connect();
- parent::__construct($params);
+ parent::__construct($structure, $cache, $logger, $params);
}
Horde_Kolab_Server_Exception::SYSTEM);
}
}
- Horde::logMessage(sprintf('The object \"%s\" has been successfully saved!',
- $uid),
- __FILE__, __LINE__, PEAR_LOG_DEBUG);
+ if (!empty($this->logger)) {
+ $this->logger->debug(sprintf('The object \"%s\" has been successfully saved!',
+ $uid));
+ }
return true;
}
throw new Horde_Kolab_Server_Exception($result,
Horde_Kolab_Server_Exception::SYSTEM);
}
- Horde::logMessage(sprintf('The object \"%s\" has been successfully deleted!',
- $uid),
- __FILE__, __LINE__, PEAR_LOG_DEBUG);
+ if (!empty($this->logger)) {
+ $this->logger(sprintf('The object \"%s\" has been successfully deleted!',
+ $uid));
+ }
return true;
}
throw new Horde_Kolab_Server_Exception($result,
Horde_Kolab_Server_Exception::SYSTEM);
}
- Horde::logMessage(sprintf('The object \"%s\" has been successfully renamed to \"%s\"!',
- $uid, $new),
- __FILE__, __LINE__, PEAR_LOG_DEBUG);
+ if (!empty($this->logger)) {
+ $this->logger->debug(sprintf('The object \"%s\" has been successfully renamed to \"%s\"!',
+ $uid, $new));
+ }
return true;
}
/**
* Construct a new Horde_Kolab_Server_Structure object.
*
- * @param Horde_Kolab_Server &$server A link to the server handler.
* @param array $params Parameter array.
*/
- public function __construct(&$server, $params = array())
+ public function __construct($params = array())
{
- $this->server = &$server;
$this->params = $params;
}
/**
+ * Set the server reference for this object.
+ *
+ * @param Horde_Kolab_Server &$server A link to the server handler.
+ */
+ public function setServer($server)
+ {
+ $this->server = $server;
+ }
+
+ /**
* Attempts to return a concrete Horde_Kolab_Server_Structure instance based
* on $driver.
*
* @throws Horde_Kolab_Server_Exception If the requested Horde_Kolab_Server_Structure
* subclass could not be found.
*/
- static public function &factory($driver, &$server, $params = array())
+ static public function &factory($driver, $params = array())
{
if (class_exists($driver)) {
$class = $driver;
} else {
$class = 'Horde_Kolab_Server_Structure_' . ucfirst(basename($driver));
if (!class_exists($class)) {
- throw new Horde_Kolab_Server_Exception(
- 'Structure type definition "' . $class . '" missing.');
+ throw new Horde_Kolab_Server_Exception('Structure type definition "' . $class . '" missing.');
}
}
- $structure = new $class($server, $params);
+ $structure = new $class($params);
return $structure;
}
*/
public function determineType($uid)
{
+ if (empty($this->server)) {
+ throw new Horde_Kolab_Server_Exception('The server reference is missing!');
+ }
$oc = $this->server->getObjectClasses($uid);
// Not a user type?
if (!in_array('kolabinetorgperson', $oc)) {
*/
public function determineType($uid)
{
+ if (empty($this->server)) {
+ throw new Horde_Kolab_Server_Exception('The server reference is missing!');
+ }
$ocs = $this->server->getObjectClasses($uid);
$ocs = array_reverse($ocs);
foreach ($ocs as $oc) {
*/
public function generateServerUid($type, $id, $info)
{
+ if (empty($this->server)) {
+ throw new Horde_Kolab_Server_Exception('The server reference is missing!');
+ }
return sprintf('%s,%s', $id, $this->server->getBaseUid());
}
*/
public function quoteForUid($id)
{
- require_once 'Net/LDAP2/Util.php';
-
$id = Net_LDAP2_Util::escape_dn_value($id);
return $id[0];
}
*/
public function quoteForFilter($part)
{
- require_once 'Net/LDAP2/Util.php';
-
$part = Net_LDAP2_Util::escape_filter_value($part);
return $part[0];
}
*
* @param array $params Parameter array.
*/
- public function __construct($params = array())
+ public function __construct(Horde_Kolab_Server_Structure $structure,
+ Horde_Cache $cache = null,
+ Horde_Log_Logger $logger = null,
+ $params = array())
{
$this->load();
if (isset($params['data'])) {
}
}
- parent::__construct($params);
+ parent::__construct($structure, $cache, $logger, $params);
if (isset($this->params['admin'])
&& isset($this->params['admin']['type'])) {
}
}
-
- Horde::logMessage(sprintf('The object \"%s\" has been successfully saved!',
- $uid),
- __FILE__, __LINE__, PEAR_LOG_DEBUG);
$this->store();
+
+ if (!empty($this->logger)) {
+ $logger->debug(sprintf('The object \"%s\" has been successfully saved!',
+ $uid));
+ }
}
/**
$uid));
}
$this->store();
- Horde::logMessage(sprintf('The object \"%s\" has been successfully deleted!',
- $uid),
- __FILE__, __LINE__, PEAR_LOG_DEBUG);
+ if (!empty($this->logger)) {
+ $logger->debug(sprintf('The object \"%s\" has been successfully deleted!',
+ $uid));
+ }
return true;
}
unset($this->data[$uid]);
}
$this->store();
- Horde::logMessage(sprintf('The object \"%s\" has been successfully renamed to \"%s\"!',
- $uid, $new),
- __FILE__, __LINE__, PEAR_LOG_DEBUG);
+ if (!empty($this->logger)) {
+ $logger->debug(sprintf('The object \"%s\" has been successfully renamed to \"%s\"!',
+ $uid, $new));
+ }
return true;
}
*/
public function testGenerateUid()
{
- $ks = &Horde_Kolab_Server::factory('none');
+ $provider = new stdClass;
+ $provider->kolab_server_driver = 'none';
+ $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap();
+ $ks = &Horde_Kolab_Server::factory($provider);
$user = new Horde_Kolab_Server_Object($ks, null, null);
$this->assertEquals(preg_replace('/[0-9a-f]*/', '', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)), '');
}
public function testCreation()
{
try {
- Horde_Kolab_Server::factory('dummy');
+ $provider = new stdClass;
+ $provider->kolab_server_driver = 'dummy';
+ $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap();
+ Horde_Kolab_Server::factory($provider);
$this->assertFail('No error!');
} catch (Horde_Kolab_Server_Exception $e) {
- $this->assertEquals($e->getMessage(),
- 'Server type definition "Horde_Kolab_Server_Dummy" missing.');
+ $this->assertEquals('Server type definition "Horde_Kolab_Server_Dummy" missing.',
+ $e->getMessage());
}
}
*/
public function testFetch()
{
- $ks = &Horde_Kolab_Server::factory('none');
+ $provider = new stdClass;
+ $provider->kolab_server_driver = 'none';
+ $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap();
+ $ks = &Horde_Kolab_Server::factory($provider);
$user = $ks->fetch('test');
$this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class($user));
- $ks = &Horde_Kolab_Server::factory('none', array('uid' => 'test'));
+ $provider = new stdClass;
+ $provider->kolab_server_driver = 'none';
+ $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap();
+ $ks = &Horde_Kolab_Server::factory($provider);
$user = $ks->fetch();
$this->assertEquals('Horde_Kolab_Server_Object_Kolab_User', get_class($user));
}
*/
public function testList()
{
- $ks = &Horde_Kolab_Server::factory('none');
+ $provider = new stdClass;
+ $provider->kolab_server_driver = 'none';
+ $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap();
+ $ks = &Horde_Kolab_Server::factory($provider);
$hash = $ks->listHash('Horde_Kolab_Server_Object');
$this->assertEquals($hash, array());
- $ks = &Horde_Kolab_Server::factory('none', array('whatever'));
+ $provider = new stdClass;
+ $provider->kolab_server_driver = 'none';
+ $provider->kolab_server_params = array('whatever');
+ $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap();
+ $ks = &Horde_Kolab_Server::factory($provider);
$hash = $ks->listHash('Horde_Kolab_Server_Object');
$this->assertEquals($hash, array());
}
*/
public function testFilterParse()
{
- $db = &Horde_Kolab_Server::factory('test', array());
+ $provider = new stdClass;
+ $provider->kolab_server_driver = 'test';
+ $provider->kolab_server_params = array();
+ $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap();
+ $db = &Horde_Kolab_Server::factory($provider);
$a = $db->parse('(a=b)');
$this->assertNoError($a);
*/
public function testSearch()
{
- $db = &Horde_Kolab_Server::factory('test',
- array('data' =>
- array(
- 'cn=a' => array(
- 'dn' => 'cn=a',
- 'data' => array(
- 'a' => '1',
- 'b' => '1',
- 'c' => '1',
- )
- ),
- 'cn=b' => array(
- 'dn' => 'cn=b',
- 'data' => array(
- 'a' => '1',
- 'b' => '2',
- 'c' => '2',
- )
- ),
- 'cn=c' => array(
- 'dn' => 'cn=c',
- 'data' => array(
- 'a' => '1',
- 'b' => '2',
- 'c' => '3',
- )
- ),
- 'cn=d' => array(
- 'dn' => 'cn=d',
- 'data' => array(
- 'a' => '2',
- 'b' => '2',
- 'c' => '1',
- )
- ),
- )
- )
+ $provider = new stdClass;
+ $provider->kolab_server_driver = 'test';
+ $provider->kolab_server_structure = new Horde_Kolab_Server_Structure_Ldap();
+ $provider->kolab_server_params = array('data' =>
+ array(
+ 'cn=a' => array(
+ 'dn' => 'cn=a',
+ 'data' => array(
+ 'a' => '1',
+ 'b' => '1',
+ 'c' => '1',
+ )
+ ),
+ 'cn=b' => array(
+ 'dn' => 'cn=b',
+ 'data' => array(
+ 'a' => '1',
+ 'b' => '2',
+ 'c' => '2',
+ )
+ ),
+ 'cn=c' => array(
+ 'dn' => 'cn=c',
+ 'data' => array(
+ 'a' => '1',
+ 'b' => '2',
+ 'c' => '3',
+ )
+ ),
+ 'cn=d' => array(
+ 'dn' => 'cn=d',
+ 'data' => array(
+ 'a' => '2',
+ 'b' => '2',
+ 'c' => '1',
+ )
+ ),
+ )
);
+ $db = &Horde_Kolab_Server::factory($provider);
$a = $db->search('(c=1)');
$this->assertNoError($a);