Allow to use different structure types for a server. This should allow
authorGunnar Wrobel <p@rdus.de>
Wed, 8 Apr 2009 20:39:08 +0000 (22:39 +0200)
committerGunnar Wrobel <p@rdus.de>
Wed, 8 Apr 2009 20:39:08 +0000 (22:39 +0200)
for more flexibility with different LDAP tree structures.

framework/Kolab_Server/lib/Horde/Kolab/Server.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Kolab.php [deleted file]
framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Kolab.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Ldap.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Test.php
framework/Kolab_Server/package.xml
framework/Kolab_Server/test/Horde/Kolab/Server/ServerTest.php

index 7ab4ebe..2bff580 100644 (file)
@@ -58,6 +58,13 @@ abstract class Horde_Kolab_Server
     protected $searches;
 
     /**
+     * The structure handler for this server.
+     *
+     * @var Horde_Kolab_Server_Structure
+     */
+    public $structure;
+
+    /**
      * Construct a new Horde_Kolab_Server object.
      *
      * @param array $params Parameter array.
@@ -69,6 +76,15 @@ abstract class Horde_Kolab_Server
             $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();
     }
@@ -328,16 +344,44 @@ abstract class Horde_Kolab_Server
     }
 
     /**
-     * Returns the set of objects supported by this server type.
+     * Returns the set of objects supported by this server.
      *
-     * @return array An array of supported search operations.
+     * @return array An array of supported objects.
+     */
+    public function getSupportedObjects()
+    {
+        return $this->structure->getSupportedObjects();
+    }
+
+    /**
+     * Determine the type of an object by its tree position and other
+     * parameters.
+     *
+     * @param string $uid The UID of the object to examine.
+     *
+     * @return string The class name of the corresponding object type.
+     *
+     * @throws Horde_Kolab_Server_Exception If the object type is unknown.
+     */
+    public function determineType($uid)
+    {
+        return $this->structure->determineType($uid);
+    }
+
+    /**
+     * Generates a UID for the given information.
+     *
+     * @param string $type The class name of the object to create.
+     * @param string $id   The id of the object.
+     * @param array  $info Any additional information about the object to create.
+     *
+     * @return string The UID.
+     *
+     * @throws Horde_Kolab_Server_Exception
      */
-    static public function getSupportedObjects()
+    protected function generateServerUid($type, $id, $info)
     {
-        $objects = array(
-            'Horde_Kolab_Server_Object',
-        );
-        return $objects;
+        return $this->structure->generateServerUid($type, $id, $info);
     }
 
     /**
@@ -528,9 +572,11 @@ abstract class Horde_Kolab_Server
     {
         $server_searches = array();
         foreach ($this->getSupportedObjects() as $sobj) {
-            $searches = call_user_func(array($sobj, 'getSearchOperations'));
-            foreach ($searches as $search) {
-                $server_searches[$search] = array('class' => $sobj);
+            if (in_array('getSearchOperations', get_class_methods($sobj))) {
+                $searches = call_user_func(array($sobj, 'getSearchOperations'));
+                foreach ($searches as $search) {
+                    $server_searches[$search] = array('class' => $sobj);
+                }
             }
         }
         return $server_searches;
@@ -586,17 +632,6 @@ abstract class Horde_Kolab_Server
     abstract public function save($uid, $data, $exists = false);
 
     /**
-     * Determine the type of a Kolab object.
-     *
-     * @param string $uid The UID of the object to examine.
-     *
-     * @return string The corresponding Kolab object type.
-     *
-     * @throws Horde_Kolab_Server_Exception
-     */
-    abstract protected function determineType($uid);
-
-    /**
      * List all objects of a specific type
      *
      * @param string $type   The type of the objects to be listed
@@ -609,19 +644,6 @@ abstract class Horde_Kolab_Server
     abstract public function listObjects($type, $params = null);
 
     /**
-     * Generates a UID for the given information.
-     *
-     * @param string $type The type of the object to create.
-     * @param string $id   The id of the object.
-     * @param array  $info Any additional information about the object to create.
-     *
-     * @return string The UID.
-     *
-     * @throws Horde_Kolab_Server_Exception
-     */
-    abstract protected function generateServerUid($type, $id, $info);
-
-    /**
      * Return the root of the UID values on this server.
      *
      * @return string The base UID on this server (base DN on ldap).
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Kolab.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Kolab.php
deleted file mode 100644 (file)
index 9445ae9..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-<?php
-/**
- * The driver for accessing the Kolab user database stored in LDAP.
- *
- * PHP version 5
- *
- * @category Kolab
- * @package  Kolab_Server
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Kolab_Server
- */
-
-/**
- * This class provides methods to deal with Kolab objects stored in
- * the standard Kolab LDAP db.
- *
- * Copyright 2008-2009 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://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_Server
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Kolab_Server
- */
-class Horde_Kolab_Server_Kolab extends Horde_Kolab_Server_Ldap
-{
-    /**
-     * Returns the set of objects supported by this server type.
-     *
-     * @return array An array of supported search operations.
-     */
-    static public function getSupportedObjects()
-    {
-        $objects = array(
-            'Horde_Kolab_Server_Object',
-            'Horde_Kolab_Server_Object_Groupofnames',
-            'Horde_Kolab_Server_Object_Kolabinetorgperson',
-            'Horde_Kolab_Server_Object_Kolabgroupofnames',
-        );
-        return $objects;
-    }
-
-    /**
-     * Determine the type of a Kolab object.
-     *
-     * @param string $dn The DN of the object to examine.
-     *
-     * @return int The corresponding Kolab object type.
-     *
-     * @throws Horde_Kolab_Server_Exception If the object type is unknown.
-     */
-    public function determineType($dn)
-    {
-        $oc = $this->getObjectClasses($dn);
-        // Not a user type?
-        if (!in_array('kolabinetorgperson', $oc)) {
-            // Is it a group?
-            if (in_array('kolabgroupofnames', $oc)) {
-                return 'Horde_Kolab_Server_Object_Kolabgroupofnames';
-            }
-            // Is it a shared Folder?
-            if (in_array('kolabsharedfolder', $oc)) {
-                return 'Horde_Kolab_Server_Object_Kolabsharedfolder';
-            }
-            return parent::determineType($dn);
-        }
-
-        $groups = $this->getGroups($dn);
-        if (!empty($groups)) {
-            if (in_array('cn=admin,cn=internal,' . $this->getBaseUid(), $groups)) {
-                return 'Horde_Kolab_Server_Object_Kolab_Administrator';
-            }
-            if (in_array('cn=maintainer,cn=internal,' . $this->getBaseUid(),
-                         $groups)) {
-                return 'Horde_Kolab_Server_Object_Kolab_Maintainer';
-            }
-            if (in_array('cn=domain-maintainer,cn=internal,' . $this->getBaseUid(),
-                         $groups)) {
-                return 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer';
-            }
-        }
-
-        if (strpos($dn, 'cn=external') !== false) {
-            return 'Horde_Kolab_Server_Object_Kolab_Address';
-        }
-
-        return 'Horde_Kolab_Server_Object_Kolab_User';
-    }
-
-    /**
-     * Generates a UID for the given information.
-     *
-     * @param string $type The type of the object to create.
-     * @param string $id   The id of the object.
-     * @param array  $info Any additional information about the object to create.
-     *
-     * @return string The DN.
-     *
-     * @throws Horde_Kolab_Server_Exception If the given type is unknown.
-     */
-    public function generateServerUid($type, $id, $info)
-    {
-        switch ($type) {
-        case 'Horde_Kolab_Server_Object_Kolab_User':
-            if (empty($info['user_type'])) {
-                return parent::generateServerUid($type, $id, $info);
-            } else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_INTERNAL) {
-                return sprintf('%s,cn=internal,%s', $id, $this->getBaseUid());
-            } else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_GROUP) {
-                return sprintf('%s,cn=groups,%s', $id, $this->getBaseUid());
-            } else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_RESOURCE) {
-                return sprintf('%s,cn=resources,%s', $id, $this->getBaseUid());
-            } else {
-                return parent::generateServerUid($type, $id, $info);
-            }
-        case 'Horde_Kolab_Server_Object_Kolab_Address':
-            return sprintf('%s,cn=external,%s', $id, $this->getBaseUid());
-        case 'Horde_Kolab_Server_Object_Kolabgroupofnames':
-        case 'Horde_Kolab_Server_Object_Kolab_Distlist':
-            if (!isset($info['visible']) || !empty($info['visible'])) {
-                return parent::generateServerUid($type, $id, $info);
-            } else {
-                return sprintf('%s,cn=internal,%s', $id, $this->getBaseUid());
-            }
-        case 'Horde_Kolab_Server_Object_Kolabsharedfolder':
-        case 'Horde_Kolab_Server_Object_Kolab_Administrator':
-        case 'Horde_Kolab_Server_Object_Kolab_Maintainer':
-        case 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer':
-        default:
-            return parent::generateServerUid($type, $id, $info);
-        }
-    }
-}
index f02934a..e814075 100644 (file)
@@ -485,51 +485,4 @@ class Horde_Kolab_Server_Ldap extends Horde_Kolab_Server
 
         return $clause;
     }
-
-    /**
-     * Determine the type of a Kolab object.
-     *
-     * @param string $uid The UID of the object to examine.
-     *
-     * @return int The corresponding Kolab object type.
-     *
-     * @throws Horde_Kolab_Server_Exception If the object type is unknown.
-     */
-    public function determineType($uid)
-    {
-        $ocs = $this->getObjectClasses($uid);
-        $ocs = array_reverse($ocs);
-        foreach ($ocs as $oc) {
-            try {
-                $class_name = 'Horde_Kolab_Server_Object_' . ucfirst(strtolower($oc));
-                Horde_Kolab_Server_Object::loadClass($class_name);
-                return $class_name;
-            } catch (Horde_Kolab_Server_Exception $e)  {
-            }
-        }
-        if ($oc == 'top') {
-            return 'Horde_Kolab_Server_Object';
-        }
-        throw new Horde_Kolab_Server_Exception(sprintf(_("Unkown object type for UID %s."),
-                                                       $uid));
-    }
-
-    /**
-     * Generates a UID for the given information.
-     *
-     * @param string $type The type of the object to create.
-     * @param string $id   The id of the object.
-     * @param array  $info Any additional information about the object to create.
-     *
-     * @return string The DN.
-     *
-     * @throws Horde_Kolab_Server_Exception If the given type is unknown.
-     */
-    public function generateServerUid($type, $id, $info)
-    {
-        switch ($type) {
-        default:
-            return sprintf('%s,%s', $id, $this->getBaseUid());
-        }
-    }
 }
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure.php
new file mode 100644 (file)
index 0000000..54b40ba
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+/**
+ * A simple structural handler for a tree of objects.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ */
+
+/**
+ * An abstract class definiing methods to deal with an object tree structure.
+ *
+ * Copyright 2009 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://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ */
+abstract class Horde_Kolab_Server_Structure
+{
+    /**
+     * A link to the server handler.
+     *
+     * @var Horde_Kolab_Server
+     */
+    protected $server;
+
+    /**
+     * Structure parameters.
+     *
+     * @var array
+     */
+    protected $params = array();
+
+    /**
+     * 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())
+    {
+        $this->server = &$server;
+        $this->params = $params;
+    }
+
+    /**
+     * Attempts to return a concrete Horde_Kolab_Server_Structure instance based
+     * on $driver.
+     *
+     * @param mixed              $driver  The type of concrete Horde_Kolab_Server
+     *                                    subclass to return.
+     * @param Horde_Kolab_Server &$server A link to the server handler .
+     * @param array              $params  A hash containing any additional
+     *                                    configuration or connection
+     *                                    parameters a subclass might need.
+     *
+     * @return Horde_Kolab_Server_Structure The newly created concrete
+     *                            Horde_Kolab_Server_Structure instance.
+     *
+     * @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())
+    {
+        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.');
+            }
+        }
+        $structure = new $class($server, $params);
+        return $structure;
+    }
+
+    /**
+     * Returns the set of objects supported by this structure.
+     *
+     * @return array An array of supported objects.
+     */
+    abstract public function getSupportedObjects();
+
+    /**
+     * Determine the type of an object by its tree position and other
+     * parameters.
+     *
+     * @param string $uid The UID of the object to examine.
+     *
+     * @return string The class name of the corresponding object type.
+     *
+     * @throws Horde_Kolab_Server_Exception If the object type is unknown.
+     */
+    abstract public function determineType($uid);
+
+    /**
+     * Generates a UID for the given information.
+     *
+     * @param string $type The class name of the object to create.
+     * @param string $id   The id of the object.
+     * @param array  $info Any additional information about the object to create.
+     *
+     * @return string The UID.
+     *
+     * @throws Horde_Kolab_Server_Exception If the given type is unknown.
+     */
+    abstract public function generateServerUid($type, $id, $info);
+}
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Kolab.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Kolab.php
new file mode 100644 (file)
index 0000000..cffd828
--- /dev/null
@@ -0,0 +1,145 @@
+<?php
+/**
+ * The driver for handling the Kolab user database structure.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ */
+
+/**
+ * This class provides methods to deal with Kolab objects stored in
+ * the standard Kolab LDAP db.
+ *
+ * Copyright 2008-2009 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://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ */
+class Horde_Kolab_Server_Structure_Kolab extends Horde_Kolab_Server_Structure_Ldap
+{
+    /**
+     * Returns the set of objects supported by this structure.
+     *
+     * @return array An array of supported objects.
+     */
+    public function getSupportedObjects()
+    {
+        return array(
+            'Horde_Kolab_Server_Object',
+            'Horde_Kolab_Server_Object_Groupofnames',
+            'Horde_Kolab_Server_Object_Kolabinetorgperson',
+            'Horde_Kolab_Server_Object_Kolabgroupofnames',
+            'Horde_Kolab_Server_Object_Kolabsharedfolder',
+            'Horde_Kolab_Server_Object_Kolab_Address',
+            'Horde_Kolab_Server_Object_Kolab_Administrator',
+            'Horde_Kolab_Server_Object_Kolab_Distlist',
+            'Horde_Kolab_Server_Object_Kolab_Domainmaintainer',
+            'Horde_Kolab_Server_Object_Kolab_Maintainer',
+            'Horde_Kolab_Server_Object_Kolab_Server',
+            'Horde_Kolab_Server_Object_Kolab_User',
+        );
+    }
+
+    /**
+     * Determine the type of an object by its tree position and other
+     * parameters.
+     *
+     * @param string $uid The UID of the object to examine.
+     *
+     * @return string The class name of the corresponding object type.
+     *
+     * @throws Horde_Kolab_Server_Exception If the object type is unknown.
+     */
+    public function determineType($uid)
+    {
+        $oc = $this->server->getObjectClasses($uid);
+        // Not a user type?
+        if (!in_array('kolabinetorgperson', $oc)) {
+            // Is it a group?
+            if (in_array('kolabgroupofnames', $oc)) {
+                return 'Horde_Kolab_Server_Object_Kolabgroupofnames';
+            }
+            // Is it a shared Folder?
+            if (in_array('kolabsharedfolder', $oc)) {
+                return 'Horde_Kolab_Server_Object_Kolabsharedfolder';
+            }
+            return parent::determineType($uid);
+        }
+
+        $groups = $this->server->getGroups($uid);
+        if (!empty($groups)) {
+            if (in_array('cn=admin,cn=internal,' . $this->server->getBaseUid(), $groups)) {
+                return 'Horde_Kolab_Server_Object_Kolab_Administrator';
+            }
+            if (in_array('cn=maintainer,cn=internal,' . $this->server->getBaseUid(),
+                         $groups)) {
+                return 'Horde_Kolab_Server_Object_Kolab_Maintainer';
+            }
+            if (in_array('cn=domain-maintainer,cn=internal,' . $this->server->getBaseUid(),
+                         $groups)) {
+                return 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer';
+            }
+        }
+
+        if (strpos($uid, 'cn=external') !== false) {
+            return 'Horde_Kolab_Server_Object_Kolab_Address';
+        }
+
+        return 'Horde_Kolab_Server_Object_Kolab_User';
+    }
+
+    /**
+     * Generates a UID for the given information.
+     *
+     * @param string $type The class name of the object to create.
+     * @param string $id   The id of the object.
+     * @param array  $info Any additional information about the object to create.
+     *
+     * @return string The UID.
+     *
+     * @throws Horde_Kolab_Server_Exception If the given type is unknown.
+     */
+    public function generateServerUid($type, $id, $info)
+    {
+        switch ($type) {
+        case 'Horde_Kolab_Server_Object_Kolab_User':
+            if (empty($info['user_type'])) {
+                return parent::generateServerUid($type, $id, $info);
+            } else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_INTERNAL) {
+                return sprintf('%s,cn=internal,%s', $id, $this->server->getBaseUid());
+            } else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_GROUP) {
+                return sprintf('%s,cn=groups,%s', $id, $this->server->getBaseUid());
+            } else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_RESOURCE) {
+                return sprintf('%s,cn=resources,%s', $id, $this->server->getBaseUid());
+            } else {
+                return parent::generateServerUid($type, $id, $info);
+            }
+        case 'Horde_Kolab_Server_Object_Kolab_Address':
+            return sprintf('%s,cn=external,%s', $id, $this->server->getBaseUid());
+        case 'Horde_Kolab_Server_Object_Kolabgroupofnames':
+        case 'Horde_Kolab_Server_Object_Kolab_Distlist':
+            if (!isset($info['visible']) || !empty($info['visible'])) {
+                return parent::generateServerUid($type, $id, $info);
+            } else {
+                return sprintf('%s,cn=internal,%s', $id, $this->server->getBaseUid());
+            }
+        case 'Horde_Kolab_Server_Object_Kolabsharedfolder':
+        case 'Horde_Kolab_Server_Object_Kolab_Administrator':
+        case 'Horde_Kolab_Server_Object_Kolab_Maintainer':
+        case 'Horde_Kolab_Server_Object_Kolab_Domainmaintainer':
+        default:
+            return parent::generateServerUid($type, $id, $info);
+        }
+    }
+}
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Structure/Ldap.php
new file mode 100644 (file)
index 0000000..ed06de1
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+/**
+ * A structural handler for the tree of objects stored in LDAP.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ */
+
+/**
+ * This class provides methods to deal with the LDAP tree structure.
+ *
+ * Copyright 2008-2009 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://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Server
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ */
+class Horde_Kolab_Server_Structure_Ldap extends Horde_Kolab_Server_Structure
+{
+    /**
+     * Returns the set of objects supported by this structure.
+     *
+     * @return array An array of supported objects.
+     */
+    public function getSupportedObjects()
+    {
+        return array(
+            'Horde_Kolab_Server_Object',
+        );
+    }
+
+    /**
+     * Determine the type of an object by its tree position and other
+     * parameters.
+     *
+     * @param string $uid The UID of the object to examine.
+     *
+     * @return string The class name of the corresponding object type.
+     *
+     * @throws Horde_Kolab_Server_Exception If the object type is unknown.
+     */
+    public function determineType($uid)
+    {
+        $ocs = $this->server->getObjectClasses($uid);
+        $ocs = array_reverse($ocs);
+        foreach ($ocs as $oc) {
+            try {
+                $class_name = 'Horde_Kolab_Server_Object_' . ucfirst(strtolower($oc));
+                Horde_Kolab_Server_Object::loadClass($class_name);
+                return $class_name;
+            } catch (Horde_Kolab_Server_Exception $e)  {
+            }
+        }
+        if ($oc == 'top') {
+            return 'Horde_Kolab_Server_Object';
+        }
+        throw new Horde_Kolab_Server_Exception(sprintf(_("Unkown object type for UID %s."),
+                                                       $uid));
+    }
+
+    /**
+     * Generates a UID for the given information.
+     *
+     * @param string $type The class name of the object to create.
+     * @param string $id   The id of the object.
+     * @param array  $info Any additional information about the object to create.
+     *
+     * @return string The UID.
+     *
+     * @throws Horde_Kolab_Server_Exception If the given type is unknown.
+     */
+    public function generateServerUid($type, $id, $info)
+    {
+        return sprintf('%s,%s', $id, $this->server->getBaseUid());
+    }
+}
index 75af6b9..b525b88 100644 (file)
@@ -25,7 +25,7 @@
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Server
  */
-class Horde_Kolab_Server_Test extends Horde_Kolab_Server_Kolab
+class Horde_Kolab_Server_Test extends Horde_Kolab_Server_Ldap
 {
 
     /**
index e443dd6..2c7ee95 100644 (file)
@@ -50,7 +50,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
       <dir name="Server">
        <file name="Exception.php" role="php" />
        <file name="File.php" role="php" />
-       <file name="Kolab.php" role="php" />
        <file name="Ldap.php" role="php" />
        <file name="MissingObjectException.php" role="php" />
        <file name="Object.php" role="php" />
@@ -73,6 +72,11 @@ http://pear.php.net/dtd/package-2.0.xsd">
          <file name="User.php" role="php" />
         </dir> <!-- /lib/Horde/Kolab/Server/Object/Kolab -->
        </dir> <!-- /lib/Horde/Kolab/Server/Object -->
+       <file name="Structure.php" role="php" />
+       <dir name="Structure">
+        <file name="Kolab.php" role="php" />
+        <file name="Ldap.php" role="php" />
+       </dir> <!-- /lib/Horde/Kolab/Server/Structure -->
        <file name="Test.php" role="php" />
        <dir name="Test">
         <file name="Search.php" role="php" />
@@ -143,7 +147,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Kolab/Test/Server.php" as="Horde/Kolab/Test/Server.php" />
    <install name="lib/Horde/Kolab/Server/Exception.php" as="Horde/Kolab/Server/Exception.php" />
    <install name="lib/Horde/Kolab/Server/File.php" as="Horde/Kolab/Server/File.php" />
-   <install name="lib/Horde/Kolab/Server/Kolab.php" as="Horde/Kolab/Server/Kolab.php" />
    <install name="lib/Horde/Kolab/Server/Ldap.php" as="Horde/Kolab/Server/Ldap.php" />
    <install name="lib/Horde/Kolab/Server/MissingObjectException.php" as="Horde/Kolab/Server/MissingObjectException.php" />
    <install name="lib/Horde/Kolab/Server/Object.php" as="Horde/Kolab/Server/Object.php" />
@@ -162,6 +165,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Kolab/Server/Object/Kolab/User.php" as="Horde/Kolab/Server/Object/Kolab/User.php" />
    <install name="lib/Horde/Kolab/Server/Object/Organizationalperson.php" as="Horde/Kolab/Server/Object/Organizationalperson.php" />
    <install name="lib/Horde/Kolab/Server/Object/Person.php" as="Horde/Kolab/Server/Object/Person.php" />
+   <install name="lib/Horde/Kolab/Server/Structure.php" as="Horde/Kolab/Server/Structure.php" />
+   <install name="lib/Horde/Kolab/Server/Structure/Kolab.php" as="Horde/Kolab/Server/Structure/Kolab.php" />
+   <install name="lib/Horde/Kolab/Server/Structure/Ldap.php" as="Horde/Kolab/Server/Structure/Ldap.php" />
    <install name="lib/Horde/Kolab/Server/Test.php" as="Horde/Kolab/Server/Test.php" />
    <install name="lib/Horde/Kolab/Server/Test/Search.php" as="Horde/Kolab/Server/Test/Search.php" />
    <install name="test/Horde/Kolab/Server/AddingObjectsTest.php" as="Horde/Kolab/Server/AddingObjectsTest.php" />
index 8275b7b..5fdc686 100644 (file)
@@ -145,7 +145,7 @@ class Horde_Kolab_Server_None extends Horde_Kolab_Server
      *
      * @return string The corresponding Kolab object type.
      */
-    protected function determineType($uid)
+    public function determineType($uid)
     {
         return 'Horde_Kolab_Server_Object_Kolab_User';
     }
@@ -240,4 +240,14 @@ class Horde_Kolab_Server_None extends Horde_Kolab_Server
         /* In the default class we just return an empty array */
         return array();
     }
+
+    /**
+     * Returns the set of objects supported by this server.
+     *
+     * @return array An array of supported objects.
+     */
+    public function getSupportedObjects()
+    {
+        return array('Horde_Kolab_Server_Object');
+    }
 }