Start splitting the factory into separate classes. Added some tests for that.
authorGunnar Wrobel <p@rdus.de>
Tue, 27 Oct 2009 23:11:27 +0000 (00:11 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 27 Oct 2009 23:11:27 +0000 (00:11 +0100)
16 files changed:
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Base.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Cleaned.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Configuration.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Base.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Injector.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Ldap.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Mock.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Constructor.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Default.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Injector.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Kolab.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Logged.php [new file with mode: 0644]
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Mapped.php [new file with mode: 0644]
framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/KolabTest.php [new file with mode: 0644]

index 1a881c3..ec2a895 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * A library for accessing the Kolab user database.
+ * The interface of Kolab server factories.
  *
  * PHP version 5
  *
@@ -12,7 +12,7 @@
  */
 
 /**
- * A factory for Kolab server objects.
+ * The interface of Kolab server factories.
  *
  * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
  *
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Server
  */
-class Horde_Kolab_Server_Factory
+interface Horde_Kolab_Server_Factory
 {
     /**
-     * Singleton instances.
+     * Returns a concrete Horde_Kolab_Server_Composite instance.
      *
-     * @var array
+     * @return Horde_Kolab_Server_Composite The newly created concrete
+     *                                      Horde_Kolab_Server_Composite
+     *                                      instance.
      */
-    static private $_instances = array();
+    public function getComposite();
 
     /**
-     * Setup the machinery to create Horde_Kolab_Server objects.
+     * Returns the conn factory.
      *
-     * @param array          $configuration The parameters required to create
-     *                                      the desired Horde_Kolab_Server object.
-     * @param Horde_Injector $injector      The object providing our dependencies.
-     *
-     * @return NULL
-     */
-    static public function setup(Horde_Injector $injector, array $configuration)
-    {
-        self::setupObjects($injector);
-        self::setupSearch($injector);
-        self::setupSchema($injector);
-
-        self::setupStructure(
-            $injector,
-            isset($configuration['structure'])
-            ? $configuration['structure'] : array()
-        );
-        unset($configuration['structure']);
-
-        self::setupConfiguration($injector, $configuration);
-
-        self::setupServer($injector);
-        self::setupComposite($injector);
-    }
-
-    /**
-     * Setup the machinery to create a Horde_Kolab_Server_Objects handler.
-     *
-     * @param Horde_Injector $injector The object providing our dependencies.
-     *
-     * @return NULL
-     */
-    static protected function setupObjects(Horde_Injector $injector)
-    {
-        $injector->bindImplementation(
-            'Horde_Kolab_Server_Objects',
-            'Horde_Kolab_Server_Objects_Base'
-        );
-    }
-
-    /**
-     * Setup the machinery to create a Horde_Kolab_Server_Structure handler.
-     *
-     * @param array          $configuration The parameters required to create
-     *                                      the desired
-     *                                      Horde_Kolab_Server_Structure handler.
-     * @param Horde_Injector $injector      The object providing our dependencies.
-     *
-     * @return NULL
-     */
-    static protected function setupStructure(
-        Horde_Injector $injector,
-        array $configuration
-    ) {
-        if (!isset($configuration['driver'])) {
-            $configuration['driver'] = 'Horde_Kolab_Server_Structure_Kolab';
-        }
-
-        switch (ucfirst(strtolower($configuration['driver']))) {
-        case 'Ldap':
-        case 'Kolab':
-            $driver = 'Horde_Kolab_Server_Structure_'
-                . ucfirst(strtolower($configuration['driver']));
-            break;
-        default:
-            $driver = $configuration['driver'];
-            break;
-        }
-
-        $injector->bindImplementation('Horde_Kolab_Server_Structure', $driver);
-    }
-
-    /**
-     * Setup the machinery to create a Horde_Kolab_Server_Search handler.
-     *
-     * @param Horde_Injector $injector The object providing our dependencies.
-     *
-     * @return NULL
+     * @return Horde_Kolab_Server_Factory_Conn The connection factory.
      */
-    static protected function setupSearch(Horde_Injector $injector)
-    {
-        $injector->bindImplementation(
-            'Horde_Kolab_Server_Search',
-            'Horde_Kolab_Server_Search_Base'
-        );
-    }
+    public function getConnectionFactory();
 
     /**
-     * Setup the machinery to create a Horde_Kolab_Server_Schema handler.
+     * Returns the server configuration parameters.
      *
-     * @param Horde_Injector $injector The object providing our dependencies.
-     *
-     * @return NULL
+     * @return array The configuration parameters.
      */
-    static protected function setupSchema(Horde_Injector $injector)
-    {
-        $injector->bindImplementation(
-            'Horde_Kolab_Server_Schema',
-            'Horde_Kolab_Server_Schema_Base'
-        );
-    }
+    public function getConfiguration();
 
     /**
-     * Inject the server configuration.
-     *
-     * @param Horde_Injector $injector      The object providing our dependencies.
-     * @param array          $configuration The parameters required to create
-     *                                      the desired Horde_Kolab_Server.
+     * Return the server connection that should be used.
      *
-     * @return NULL
+     * @return Horde_Kolab_Server The Horde_Kolab_Server connection.
      */
-    static protected function setupConfiguration(
-        Horde_Injector $injector,
-        array $configuration
-    ) {
-        $injector->setInstance('Horde_Kolab_Server_Config', $configuration);
-    }
+    public function getServer();
 
     /**
-     * Setup the machinery to create a Horde_Kolab_Server.
-     *
-     * @param array          $configuration The parameters required to create
-     *                                      the desired Horde_Kolab_Server.
-     * @param Horde_Injector $injector      The object providing our dependencies.
+     * Return the server that should be used.
      *
-     * @return NULL
+     * @return Horde_Kolab_Server_Connection The connection.
      */
-    static protected function setupServer(Horde_Injector $injector) {
-        $injector->bindFactory(
-            'Horde_Kolab_Server',
-            'Horde_Kolab_Server_Factory',
-            'getServer'
-        );
-    }
+    public function getConnection();
 
     /**
-     * Attempts to return a concrete Horde_Kolab_Server instance.
+     * Return the object handler that should be used.
      *
-     * @param Horde_Injector $injector The object providing our dependencies.
-     *
-     * @return Horde_Kolab_Server The newly created concrete Horde_Kolab_Server
-     *                            instance.
+     * @return Horde_Kolab_Server_Objects The handler for objects on the server.
      */
-    static public function getServer(Horde_Injector $injector)
-    {
-        $configuration = $injector->getInstance('Horde_Kolab_Server_Config');
-
-        if (empty($configuration['driver'])) {
-            $configuration['driver'] = 'Ldap';
-        }
-
-        if (isset($configuration['params'])) {
-            $params = $configuration['params'];
-        } else {
-            $params = $configuration;
-        }
-
-        $driver = ucfirst(strtolower($configuration['driver']));
-        switch ($driver) {
-        case 'Ldap':
-        case 'Test':
-        case 'File':
-            $server = self::getLdapServer($driver, $params);
-            break;
-        default:
-            throw new Horde_Kolab_Server_Exception('Invalid server configuration!');
-        }
-
-        if (isset($params['map'])) {
-            $server = new Horde_Kolab_Server_Mapped($server, $params['map']);
-        }
-        if (isset($configuration['logger'])) {
-            $server = new Horde_Kolab_Server_Logged($server, $configuration['logger']);
-        }
-        if (isset($configuration['cache'])) {
-            $server = new Horde_Kolab_Server_Cached($server, $configuration['cache']);
-        }
-
-        return $server;
-    }
+    public function getObjects();
 
     /**
-     * Attempts to return a concrete Horde_Kolab_Server_Ldap instance.
+     * Return the structural representation that should be used.
      *
-     * @param array $params LDAP connection parameters.
-     *
-     * @return Horde_Kolab_Server_Ldap The newly created concrete
-     *                                 Horde_Kolab_Server_Ldap instance.
+     * @return Horde_Kolab_Server_Structure The representation of the db
+     *                                      structure.
      */
-    static protected function getLdapServer($driver, array $params)
-    {
-        if (!isset($params['basedn'])) {
-            throw new Horde_Kolab_Server_Exception('The base DN is missing');
-        }
-
-        if (isset($params['server'])) {
-            $params['host'] = $params['server'];
-            unset($params['server']);
-        }
-
-        if (isset($params['phpdn'])) {
-            $params['binddn'] = $params['phpdn'];
-            unset($params['phpdn']);
-        }
-
-        if (isset($params['phppw'])) {
-            $params['bindpw'] = $params['phppw'];
-            unset($params['phppw']);
-        }
-
-        //@todo: Place this is a specific connection factory.
-        switch ($driver) {
-        case 'Ldap':
-            $ldap_read = new Net_LDAP2($params);
-            if (isset($params['host_master'])) {
-                $params['host'] = $params['host_master'];
-                $ldap_write = new Net_LDAP2($params);
-                $connection = new Horde_Kolab_Server_Connection_Splittedldap(
-                    $ldap_read, $ldap_write
-                );
-            } else {
-                $connection = new Horde_Kolab_Server_Connection_Simpleldap(
-                    $ldap_read
-                );
-            }
-            break;
-        case 'File':
-        case 'Test':
-            $connection = new Horde_Kolab_Server_Connection_Mock($params);
-            break;
-        }
-
-        if (!isset($params['filter'])) {
-            $server = new Horde_Kolab_Server_Ldap_Standard(
-                $connection,
-                $params['basedn']
-            );
-        } else {
-            $server = new Horde_Kolab_Server_Ldap_Filtered(
-                $connection,
-                $params['basedn'],
-                $params['filter']
-            );
-        }
-        return $server;
-    }
+    public function getStructure();
 
     /**
-     * Setup the machinery to create a Horde_Kolab_Server_Composite server.
-     *
-     * @param Horde_Injector $injector The object providing our dependencies.
+     * Return the search handler that should be used.
      *
-     * @return NULL
+     * @return Horde_Kolab_Server_Search The search handler.
      */
-    static protected function setupComposite(Horde_Injector $injector)
-    {
-        /**
-         * Nothing to do here for now as class and interface name are the same.
-         */
-    }
+    public function getSearch();
 
     /**
-     * Attempts to return a reference to a concrete Horde_Kolab_Server
-     * instance based on $driver. It will only create a new instance
-     * if no Horde_Kolab_Server instance with the same parameters currently
-     * exists.
+     * Return the db schema representation that should be used.
      *
-     * This method must be invoked as:
-     * <code>
-     *   $var = &Horde_Kolab_Server::singleton()
-     * </code>
-     *
-     * @param array $params An array of parameters.
-     *
-     * @return Horde_Kolab_Server The concrete Horde_Kolab_Server reference.
+     * @return Horde_Kolab_Server_Schema The db schema representation.
      */
-    static public function &singleton($params = array())
-    {
-        global $conf;
-
-        if (empty($params) && isset($conf['kolab']['ldap'])) {
-            $params = $conf['kolab']['ldap'];
-        }
-
-        ksort($params);
-        $signature = hash('md5', serialize($params));
-        if (!isset(self::$_instances[$signature])) {
-            /** @todo: The caching decorator is still missing.
-/*             $params['cache'] = Horde_Cache::singleton( */
-/*                 $GLOBALS['conf']['cache']['driver'], */
-/*                 //@todo: Can we omit Horde:: here? */
-/*                 Horde::getDriverConfig( */
-/*                     'cache', */
-/*                     $GLOBALS['conf']['cache']['driver'] */
-/*                 ) */
-/*             ); */
-            $params['logger'] = Horde::getLogger();
-            $injector = new Horde_Injector(new Horde_Injector_TopLevel());
-            self::setup($injector, $params);
-            self::$_instances[$signature] = $injector->getInstance(
-                'Horde_Kolab_Server'
-            );
-        }
-
-        return self::$_instances[$signature];
-    }
+    public function getSchema();
 }
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Base.php
new file mode 100644 (file)
index 0000000..2f22f3d
--- /dev/null
@@ -0,0 +1,141 @@
+<?php
+/**
+ * Basic server factory functionality.
+ *
+ * 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
+ */
+
+/**
+ * Basic server factory functionality.
+ *
+ * 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
+ */
+abstract class Horde_Kolab_Server_Factory_Base
+implements Horde_Kolab_Server_Factory
+{
+    /**
+     * The connection factory.
+     *
+     * @param Horde_Kolab_Server_Factory_Core
+     */
+    private $_conn_factory;
+
+    /**
+     * The server configuration parameters
+     *
+     * @param array
+     */
+    private $_configuration;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Kolab_Server_Factory_Conn $factory The server connection
+     *                                                 factory.
+     * @param array                           $config  Configuration
+     *                                                 parameters for the
+     *                                                 server.
+     */
+    public function __construct(
+        Horde_Kolab_Server_Factory_Conn $factory,
+        array $config
+    ) {
+        $this->_conn_factory  = $factory;
+        $this->_configuration = $config;
+    }
+
+    /**
+     * Returns the conn factory.
+     *
+     * @return Horde_Kolab_Server_Factory_Conn The connection factory.
+     */
+    public function getConnectionFactory()
+    {
+        return $this->_conn_factory;
+    }
+
+    /**
+     * Returns the server configuration parameters.
+     *
+     * @return array The configuration parameters.
+     */
+    public function getConfiguration()
+    {
+        return $this->_configuration;
+    }
+
+    /**
+     * Return the server connection that should be used.
+     *
+     * @return Horde_Kolab_Server The Horde_Kolab_Server connection.
+     */
+    public function getServer()
+    {
+        $configuration = $this->getConfiguration();
+        if (!isset($configuration['basedn'])) {
+            throw new Horde_Kolab_Server_Exception('The base DN is missing');
+        }
+
+        $connection = $this->getConnection();
+
+        if (!isset($configuration['filter'])) {
+            $server = new Horde_Kolab_Server_Ldap_Standard(
+                $connection,
+                $configuration['basedn']
+            );
+        } else {
+            $server = new Horde_Kolab_Server_Ldap_Filtered(
+                $connection,
+                $configuration['basedn'],
+                $configuration['filter']
+            );
+        }
+        return $server;
+    }
+
+    /**
+     * Return the server that should be used.
+     *
+     * @return Horde_Kolab_Server_Connection The connection.
+     */
+    public function getConnection()
+    {
+        $factory = $this->getConnectionFactory();
+        $factory->setConfiguration($this->getConfiguration());
+        return $factory->getConnection();
+    }
+
+    /**
+     * Returns a concrete Horde_Kolab_Server_Composite instance.
+     *
+     * @return Horde_Kolab_Server_Composite The newly created concrete
+     *                                      Horde_Kolab_Server_Composite
+     *                                      instance.
+     */
+    public function getComposite()
+    {
+        $composite = new Horde_Kolab_Server_Composite(
+            $this->getServer(),
+            $this->getObjects(),
+            $this->getStructure(),
+            $this->getSearch(),
+            $this->getSchema()
+        );
+        return $composite;
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Cleaned.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Cleaned.php
new file mode 100644 (file)
index 0000000..5764453
--- /dev/null
@@ -0,0 +1,144 @@
+<?php
+/**
+ * A factory decorator that adds cleaning to the generated instances.
+ *
+ * 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
+ */
+
+/**
+ * A factory decorator that adds cleaning to the generated instances.
+ *
+ * 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
+ */
+class Horde_Kolab_Server_Factory_Cleaned
+implements Horde_Kolab_Server_Factory
+{
+    /**
+     * The factory used for creating the instances.
+     *
+     * @var Horde_Kolab_Server_Factory
+     */
+    private $_factory;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Kolab_Server_Factory $factory The base factory.
+     */
+    public function __construct(Horde_Kolab_Server_Factory $factory)
+    {
+        $this->_factory = $factory;
+        $this->_mapping = $mapping;
+    }
+
+    /**
+     * Returns the conn factory.
+     *
+     * @return Horde_Kolab_Server_Factory_Conn The connection factory.
+     */
+    public function getConnectionFactory()
+    {
+        return $this->_factory->getConnectionFactory();
+    }
+
+    /**
+     * Returns the server configuration parameters.
+     *
+     * @return array The configuration parameters.
+     */
+    public function getConfiguration()
+    {
+        return $this->_factory->getConfiguration();
+    }
+
+    /**
+     * Return the server connection that should be used.
+     *
+     * @return Horde_Kolab_Server The Horde_Kolab_Server connection.
+     */
+    public function getServer()
+    {
+        $server = $this->_factory->getServer();
+        $server = new Horde_Kolab_Server_Cleaned($server);
+        return $server;
+    }
+
+    /**
+     * Return the server that should be used.
+     *
+     * @return Horde_Kolab_Server_Connection The connection.
+     */
+    public function getConnection()
+    {
+        return $this->_factory->getConnection();
+    }
+
+    /**
+     * Returns a concrete Horde_Kolab_Server_Composite instance.
+     *
+     * @return Horde_Kolab_Server_Composite The newly created concrete
+     *                                      Horde_Kolab_Server_Composite
+     *                                      instance.
+     */
+    public function getComposite()
+    {
+        return $this->_factory->getComposite();
+    }
+
+    /**
+     * Return the object handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Objects The handler for objects on the server.
+     */
+    public function getObjects()
+    {
+        return $this->_factory->getObjects();
+    }
+
+    /**
+     * Return the structural representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Structure The representation of the db
+     *                                      structure.
+     */
+    public function getStructure()
+    {
+        return $this->_factory->getStructure();
+    }
+
+    /**
+     * Return the search handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Search The search handler.
+     */
+    public function getSearch()
+    {
+        return $this->_factory->getSearch();
+    }
+
+    /**
+     * Return the db schema representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Schema The db schema representation.
+     */
+    public function getSchema()
+    {
+        return $this->_factory->getSchema();
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Configuration.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Configuration.php
new file mode 100644 (file)
index 0000000..2a07597
--- /dev/null
@@ -0,0 +1,170 @@
+<?php
+/**
+ * A factory that receives all required details via configuration parameters.
+ *
+ * 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
+ */
+
+/**
+ * A factory that receives all required details via configuration parameters.
+ *
+ * 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_Factory_Configuration
+implements Horde_Kolab_Server_Factory
+{
+    /**
+     * Configuration parameters for the server.
+     *
+     * @var array
+     */
+    private $_configuration;
+
+    /**
+     * The factory used for creating the instances.
+     *
+     * @var Horde_Kolab_Server_Factory
+     */
+    private $_factory;
+
+    /**
+     * Constructor.
+     *
+     * @param array $config Configuration parameters for the server.
+     */
+    public function __construct(
+        Horde_Kolab_Server_Factory $factory,
+        array $config
+    ) {
+        $this->_configuration = $config;
+
+        if (isset($config['logger'])) {
+            $factory = new Horde_Kolab_Server_Factory_Logged(
+                $factory, $config['logger']
+            );
+        }
+
+        if (isset($config['map'])) {
+            $factory = new Horde_Kolab_Server_Factory_Mapped(
+                $factory, $config['map']
+            );
+        }
+
+        if (!empty($config['cleanup'])) {
+            $factory = new Horde_Kolab_Server_Factory_Cleaned(
+                $factory, $config['map']
+            );
+        }
+
+        $this->_factory = $factory;
+    }
+
+    /**
+     * Returns the conn factory.
+     *
+     * @return Horde_Kolab_Server_Factory_Conn The connection factory.
+     */
+    public function getConnectionFactory()
+    {
+        return $this->_factory->getConnectionFactory();
+    }
+
+    /**
+     * Returns the server configuration parameters.
+     *
+     * @return array The configuration parameters.
+     */
+    public function getConfiguration()
+    {
+        return $this->_factory->getConfiguration();
+    }
+
+    /**
+     * Return the server connection that should be used.
+     *
+     * @return Horde_Kolab_Server The Horde_Kolab_Server connection.
+     */
+    public function getServer()
+    {
+        return $this->_factory->getServer();
+    }
+
+    /**
+     * Return the server that should be used.
+     *
+     * @return Horde_Kolab_Server_Connection The connection.
+     */
+    public function getConnection()
+    {
+        return $this->_factory->getConnection();
+    }
+
+    /**
+     * Returns a concrete Horde_Kolab_Server_Composite instance.
+     *
+     * @return Horde_Kolab_Server_Composite The newly created concrete
+     *                                      Horde_Kolab_Server_Composite
+     *                                      instance.
+     */
+    public function getComposite()
+    {
+        return $this->_factory->getComposite();
+    }
+
+    /**
+     * Return the object handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Objects The handler for objects on the server.
+     */
+    public function getObjects()
+    {
+        return $this->_factory->getObjects();
+    }
+
+    /**
+     * Return the structural representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Structure The representation of the db
+     *                                      structure.
+     */
+    public function getStructure()
+    {
+        return $this->_factory->getStructure();
+    }
+
+    /**
+     * Return the search handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Search The search handler.
+     */
+    public function getSearch()
+    {
+        return $this->_factory->getSearch();
+    }
+
+    /**
+     * Return the db schema representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Schema The db schema representation.
+     */
+    public function getSchema()
+    {
+        return $this->_factory->getSchema();
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn.php
new file mode 100644 (file)
index 0000000..81fb120
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+/**
+ * The interface of Kolab server connection factories.
+ *
+ * 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
+ */
+
+/**
+ * The interface of Kolab server connection factories.
+ *
+ * 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
+ */
+interface Horde_Kolab_Server_Factory_Conn
+{
+    /**
+     * Set the connection configuration.
+     *
+     * @param array $configuration The configuration parameters.
+     *
+     * @return NULL
+     */
+    public function setConfiguration(array $configuration);
+
+    /**
+     * Return the server connection that should be used.
+     *
+     * @return Horde_Kolab_Server_Connection The server connection.
+     */
+    public function getConnection();
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Base.php
new file mode 100644 (file)
index 0000000..3c96143
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+/**
+ * A base connection factory definition.
+ *
+ * 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
+ */
+
+/**
+ * A base connection factory definition.
+ *
+ * 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_Factory_Conn_Base
+implements Horde_Kolab_Server_Factory_Conn
+{
+    /**
+     * Connection parameters.
+     *
+     * @var array
+     */
+    private $_configuration;
+
+    /**
+     * Set the connection configuration.
+     *
+     * @param array $configuration The configuration parameters.
+     *
+     * @return NULL
+     */
+    public function setConfiguration(array $configuration)
+    {
+        if (!isset($configuration['basedn'])) {
+            throw new Horde_Kolab_Server_Exception('The base DN is missing');
+        }
+
+        if (isset($configuration['server'])) {
+            $configuration['host'] = $configuration['server'];
+            unset($configuration['server']);
+        }
+
+        if (isset($configuration['phpdn'])) {
+            $configuration['binddn'] = $configuration['phpdn'];
+            unset($configuration['phpdn']);
+        }
+
+        if (isset($configuration['phppw'])) {
+            $configuration['bindpw'] = $configuration['phppw'];
+            unset($configuration['phppw']);
+        }
+
+        $this->_configuration = $configuration;
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Injector.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Injector.php
new file mode 100644 (file)
index 0000000..9027b9a
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/**
+ * A factory that generates connections using the Horde_Injector.
+ *
+ * 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
+ */
+
+/**
+ * A factory that generates connections using the Horde_Injector.
+ *
+ * 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
+ */
+class Horde_Kolab_Server_Factory_Conn_Injector
+extends Horde_Kolab_Server_Factory_Conn_Base
+{
+    /**
+     * The injector providing our context.
+     *
+     * @var Horde_Injector
+     */
+    private $_injector;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Injector The injector to use.
+     */
+    public function __construct(Horde_Injector $injector)
+    {
+        $this->_injector = $injector;
+    }
+
+    /**
+     * Return the server connection that should be used.
+     *
+     * @return Horde_Kolab_Server_Connection The server connection.
+     */
+    public function getConnection()
+    {
+        $factory = $this->_injector->getInstance(
+            'Horde_Kolab_Server_Factory_Conn'
+        );
+        $factory->setConfiguration(
+            $this->_injector->getInstance(
+                'Horde_Kolab_Server_Configuration'
+            )
+        );
+        $connection = $factory->getConnection();
+        return $connection;
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Ldap.php
new file mode 100644 (file)
index 0000000..f53b1a9
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * A factory that generates LDAP connections.
+ *
+ * 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
+ */
+
+/**
+ * A factory that generates LDAP connections.
+ *
+ * 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
+ */
+class Horde_Kolab_Server_Factory_Conn_Ldap
+extends Horde_Kolab_Server_Factory_Conn_Base
+{
+    /**
+     * Return the server connection that should be used.
+     *
+     * @return Horde_Kolab_Server_Connection The server connection.
+     */
+    public function getConnection()
+    {
+        $ldap_read = new Net_LDAP2($params);
+        if (isset($params['host_master'])) {
+            $params['host'] = $params['host_master'];
+            $ldap_write = new Net_LDAP2($params);
+            $connection = new Horde_Kolab_Server_Connection_Splittedldap(
+                $ldap_read, $ldap_write
+            );
+        } else {
+            $connection = new Horde_Kolab_Server_Connection_Simpleldap(
+                $ldap_read
+            );
+        }
+        return $connection;
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Mock.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Mock.php
new file mode 100644 (file)
index 0000000..5cbdcf4
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * A factory that generates mock connections.
+ *
+ * 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
+ */
+
+/**
+ * A factory that generates mock connections.
+ *
+ * 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
+ */
+class Horde_Kolab_Server_Factory_Conn_Mock
+extends Horde_Kolab_Server_Factory_Conn_Base
+{
+    /**
+     * Return the server connection that should be used.
+     *
+     * @return Horde_Kolab_Server_Connection The server connection.
+     */
+    public function getConnection()
+    {
+        $connection = new Horde_Kolab_Server_Connection_Mock(
+            $this->_configuration
+        );
+        return $connection;
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Constructor.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Constructor.php
new file mode 100644 (file)
index 0000000..f9e26d5
--- /dev/null
@@ -0,0 +1,133 @@
+<?php
+/**
+ * A Kolab server factory that receives all required details via the
+ * factory constructor.
+ *
+ * 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
+ */
+
+/**
+ * A Kolab server factory that receives all required details via the
+ * factory constructor.
+ *
+ * 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_Factory_Constructor
+extends Horde_Kolab_Server_Factory_Base
+{
+    /**
+     * The implementation representing the db structur.
+     *
+     * @param Horde_Kolab_Server_Structure
+     */
+    private $_structure;
+
+    /**
+     * The search handler.
+     *
+     * @param Horde_Kolab_Server_Search
+     */
+    private $_search;
+
+    /**
+     * Handles the db schema.
+     *
+     * @param Horde_Kolab_Server_Schema
+     */
+    private $_schema;
+
+    /**
+     * The object handler.
+     *
+     * @param Horde_Kolab_Server_Objects
+     */
+    private $_objects;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Kolab_Server_Factory_Conn $factory   The connection
+     *                                                   factory.
+     * @param Horde_Kolab_Server_Objects      $objects   The object handler.
+     * @param Horde_Kolab_Server_Structure    $structure The implementation
+     *                                                   representing the db
+     *                                                   structure.
+     * @param Horde_Kolab_Server_Search       $search    The search handler.
+     * @param Horde_Kolab_Server_Schema       $schema    Handles the db schema.
+     * @param array                           $config    Configuration
+     *                                                   parameters for the
+     *                                                   server.
+     */
+    public function __construct(
+        Horde_Kolab_Server_Factory_Conn $factory,
+        Horde_Kolab_Server_Objects $objects,
+        Horde_Kolab_Server_Structure $structure,
+        Horde_Kolab_Server_Search $search,
+        Horde_Kolab_Server_Schema $schema,
+        array $config
+    ) {
+        parent::__construct($factory, $config);
+
+        $this->_objects       = $objects;
+        $this->_structure     = $structure;
+        $this->_search        = $search;
+        $this->_schema        = $schema;
+    }
+
+    /**
+     * Return the object handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Objects The handler for objects on the server.
+     */
+    public function getObjects()
+    {
+        return $this->_objects;
+    }
+
+    /**
+     * Return the structural representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Structure The representation of the db
+     *                                      structure.
+     */
+    public function getStructure()
+    {
+        return $this->_structure;
+    }
+
+    /**
+     * Return the search handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Search The search handler.
+     */
+    public function getSearch()
+    {
+        return $this->_search;
+    }
+
+    /**
+     * Return the db schema representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Schema The db schema representation.
+     */
+    public function getSchema()
+    {
+        return $this->_schema;
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Default.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Default.php
new file mode 100644 (file)
index 0000000..a120070
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/**
+ * A Kolab server factory providing defaults where applicable.
+ *
+ * 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
+ */
+
+/**
+ * A Kolab server factory providing defaults where applicable.
+ *
+ * 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_Factory_Default
+extends Horde_Kolab_Server_Factory_Base
+{
+    /**
+     * Return the object handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Objects The handler for objects on the server.
+     */
+    public function getObjects()
+    {
+        $objects = new Horde_Kolab_Server_Objects_Base();
+        return $objects;
+    }
+
+    /**
+     * Return the search handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Search The search handler.
+     */
+    public function getSearch()
+    {
+        $search = new Horde_Kolab_Server_Search_Base();
+        return $search;
+    }
+
+    /**
+     * Return the db schema representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Schema The db schema representation.
+     */
+    public function getSchema()
+    {
+        $schema = new Horde_Kolab_Server_Schema_Base();
+        return $schema;
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Injector.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Injector.php
new file mode 100644 (file)
index 0000000..1e03e7a
--- /dev/null
@@ -0,0 +1,342 @@
+<?php
+/**
+ * A library for accessing the Kolab user database.
+ *
+ * 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
+ */
+
+/**
+ * A factory for Kolab server objects.
+ *
+ * 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_Factory_Injector
+implements Horde_Kolab_Server_Factory
+{
+    /**
+     * The conn factory class.
+     *
+     * @param string
+     */
+    private $_conn_factory;
+
+    /**
+     * Configuration parameters for the server.
+     *
+     * @var array
+     */
+    private $_configuration;
+
+    /**
+     * The injector.
+     *
+     * @var Horde_Injector
+     */
+    private $_injector;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Injector $injector The injector to use.
+     */
+    public function __construct(
+        Horde_Injector $injector
+    ) {
+        $this->_conn_factory  = $factory;
+        $this->_configuration = $config;
+        $this->_injector      = $injector;
+        $this->_setup();
+    }
+
+    /**
+     * Prepares the injector with basic configuration information.
+     *
+     * @param string         $factory  The class name of the conn connection
+     *                                 factory.
+     * @param array          $config   Configuration parameters for the server.
+     * @param Horde_Injector $injector The injector to use.
+     *
+     * @return NULL
+     */
+    static public function setup(
+        $factory,
+        array $config,
+        Horde_Injector $injector
+    ) {
+        self::_setupConfiguration($config, $injector);
+        self::_setupConnectionFactory($factory, $injector);
+    }
+
+    /**
+     * Inject the server configuration.
+     *
+     * @param array          $config   Configuration parameters for the server.
+     * @param Horde_Injector $injector The injector to use.
+     *
+     * @return NULL
+     */
+    static private function _setupConfiguration(
+        array $config,
+        Horde_Injector $injector
+    ) {
+        $injector->setInstance(
+            'Horde_Kolab_Server_Config', $config
+        );
+    }
+
+    /**
+     * Setup the machinery to create a Horde_Kolab_Server_Factory_Conn.
+     *
+     * @param string         $factory  The class name of the conn connection
+     *                                 factory.
+     * @param Horde_Injector $injector The injector to use.
+     *
+     * @return NULL
+     */
+    static private function _setupConnectionFactory(
+        $factory,
+        Horde_Injector $injector
+    ) {
+        $injector->bindImplementation(
+            'Horde_Kolab_Server_Factory_Conn', $factory
+        );
+    }
+
+    /**
+     * Setup the machinery to create Horde_Kolab_Server objects.
+     *
+     * @return NULL
+     */
+    private function _setup()
+    {
+        $this->_setupObjects();
+        $this->_setupSearch();
+        $this->_setupSchema();
+        $this->_setupStructure();
+        $this->_setupConnection();
+        $this->_setupServer();
+        $this->_setupComposite();
+    }
+
+    /**
+     * Setup the machinery to create a Horde_Kolab_Server_Objects handler.
+     *
+     * @return NULL
+     */
+    private function _setupObjects()
+    {
+        $this->_injector->bindImplementation(
+            'Horde_Kolab_Server_Objects',
+            'Horde_Kolab_Server_Objects_Base'
+        );
+    }
+
+    /**
+     * Setup the machinery to create a Horde_Kolab_Server_Search handler.
+     *
+     * @return NULL
+     */
+    private function _setupSearch()
+    {
+        $this->_injector->bindImplementation(
+            'Horde_Kolab_Server_Search',
+            'Horde_Kolab_Server_Search_Base'
+        );
+    }
+
+    /**
+     * Setup the machinery to create a Horde_Kolab_Server_Schema handler.
+     *
+     * @return NULL
+     */
+    private function _setupSchema()
+    {
+        $this->_injector->bindImplementation(
+            'Horde_Kolab_Server_Schema',
+            'Horde_Kolab_Server_Schema_Base'
+        );
+    }
+
+    /**
+     * Setup the machinery to create a Horde_Kolab_Server_Structure handler.
+     *
+     * @return NULL
+     */
+    private function _setupStructure()
+    {
+        if (!isset($this->_configuration['structure']['driver'])) {
+            $driver = 'Horde_Kolab_Server_Structure_Kolab';
+        } else {
+            $driver = $this->_configuration['structure']['driver'];
+        }
+
+        $injector->bindImplementation('Horde_Kolab_Server_Structure', $driver);
+    }
+
+    /**
+     * Setup the machinery to create a Horde_Kolab_Server.
+     *
+     * @return NULL
+     */
+    private function _setupConnection()
+    {
+        $injector->bindFactory(
+            'Horde_Kolab_Server_Connection',
+            'Horde_Kolab_Server_Factory_Conn_Injector',
+            'getConnection'
+        );
+    }
+
+    /**
+     * Setup the machinery to create a Horde_Kolab_Server.
+     *
+     * @return NULL
+     */
+    private function _setupServer()
+    {
+        $injector->bindFactory(
+            'Horde_Kolab_Server',
+            'Horde_Kolab_Server_Factory_Injector',
+            'getServer'
+        );
+    }
+
+    /**
+     * Setup the machinery to create a Horde_Kolab_Server_Composite server.
+     *
+     * @return NULL
+     */
+    private function _setupComposite()
+    {
+        /**
+         * Nothing to do here for now as class and interface name are the same.
+         */
+    }
+
+    /**
+     * Return the conn server connection that should be used.
+     *
+     * @return Horde_Kolab_Server The Horde_Kolab_Server connection.
+     */
+    public function getConnectionFactory()
+    {
+        return $this->_injector->getInstance('Horde_Kolab_Server_Factory_Conn');
+    }
+
+    /**
+     * Return the conn server connection that should be used.
+     *
+     * @return Horde_Kolab_Server The Horde_Kolab_Server connection.
+     */
+    public function getConnection()
+    {
+        return $this->_injector->getInstance('Horde_Kolab_Server_Connection');
+    }
+
+    /**
+     * Returns the server configuration parameters.
+     *
+     * @return array The configuration parameters.
+     */
+    public function getConfiguration()
+    {
+        return $this->_injector->getInstance('Horde_Kolab_Server_Configuration');
+    }
+
+    /**
+     * Return the server connection that should be used.
+     *
+     * @return Horde_Kolab_Server The Horde_Kolab_Server connection.
+     */
+    public function getServer()
+    {
+        $configuration = $this->getConfiguration();
+        if (!isset($configuration['basedn'])) {
+            throw new Horde_Kolab_Server_Exception('The base DN is missing');
+        }
+
+        $connection = $this->getConnection();
+
+        if (!isset($configuration['filter'])) {
+            $server = new Horde_Kolab_Server_Ldap_Standard(
+                $connection,
+                $configuration['basedn']
+            );
+        } else {
+            $server = new Horde_Kolab_Server_Ldap_Filtered(
+                $connection,
+                $configuration['basedn'],
+                $configuration['filter']
+            );
+        }
+        return $server;
+    }
+
+    /**
+     * Return the object handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Objects The handler for objects on the server.
+     */
+    public function getObjects()
+    {
+        return $this->_injector->getInstance('Horde_Kolab_Server_Objects');
+    }
+
+    /**
+     * Return the structural representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Structure The representation of the db
+     *                                      structure.
+     */
+    public function getStructure()
+    {
+        return $this->_injector->getInstance('Horde_Kolab_Server_Structure');
+    }
+
+    /**
+     * Return the search handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Search The search handler.
+     */
+    public function getSearch()
+    {
+        return $this->_injector->getInstance('Horde_Kolab_Server_Search');
+    }
+
+    /**
+     * Return the db schema representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Schema The db schema representation.
+     */
+    public function getSchema()
+    {
+        return $this->_injector->getInstance('Horde_Kolab_Server_Schema');
+    }
+
+    /**
+     * Returns a concrete Horde_Kolab_Server_Composite instance.
+     *
+     * @return Horde_Kolab_Server_Composite The newly created concrete
+     *                                      Horde_Kolab_Server_Composite
+     *                                      instance.
+     */
+    public function getComposite()
+    {
+        return $this->_injector->getInstance('Horde_Kolab_Server_Composite');
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Kolab.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Kolab.php
new file mode 100644 (file)
index 0000000..6861fe9
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * A Kolab server factory providing the Kolab default.
+ *
+ * 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
+ */
+
+/**
+ * A Kolab server factory providing the Kolab default.
+ *
+ * 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
+ */
+class Horde_Kolab_Server_Factory_Kolab
+extends Horde_Kolab_Server_Factory_Default
+{
+    /**
+     * Return the structural representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Structure The representation of the db
+     *                                      structure.
+     */
+    public function getStructure()
+    {
+        $structure = new Horde_Kolab_Server_Structure_Kolab();
+        return $structure;
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Logged.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Logged.php
new file mode 100644 (file)
index 0000000..54cca83
--- /dev/null
@@ -0,0 +1,152 @@
+<?php
+/**
+ * A factory decorator that adds logging to the generated instances.
+ *
+ * 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
+ */
+
+/**
+ * A factory decorator that adds logging to the generated instances.
+ *
+ * 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_Factory_Logged
+implements Horde_Kolab_Server_Factory
+{
+    /**
+     * The factory used for creating the instances.
+     *
+     * @var Horde_Kolab_Server_Factory
+     */
+    private $_factory;
+
+    /**
+     * The logger.
+     *
+     * @var mixed
+     */
+    private $_logger;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Kolab_Server_Factory $factory The base factory.
+     * @param mixed                       $logger  The logger isntance.
+     */
+    public function __construct(Horde_Kolab_Server_Factory $factory, $logger)
+    {
+        $this->_factory = $factory;
+        $this->_logger  = $logger;
+    }
+
+    /**
+     * Returns the conn factory.
+     *
+     * @return Horde_Kolab_Server_Factory_Conn The connection factory.
+     */
+    public function getConnectionFactory()
+    {
+        return $this->_factory->getConnectionFactory();
+    }
+
+    /**
+     * Returns the server configuration parameters.
+     *
+     * @return array The configuration parameters.
+     */
+    public function getConfiguration()
+    {
+        return $this->_factory->getConfiguration();
+    }
+
+    /**
+     * Return the server connection that should be used.
+     *
+     * @return Horde_Kolab_Server The Horde_Kolab_Server connection.
+     */
+    public function getServer()
+    {
+        $server = $this->_factory->getServer();
+        $server = new Horde_Kolab_Server_Logged($server);
+        return $server;
+    }
+
+    /**
+     * Return the server that should be used.
+     *
+     * @return Horde_Kolab_Server_Connection The connection.
+     */
+    public function getConnection()
+    {
+        return $this->_factory->getConnection();
+    }
+
+    /**
+     * Returns a concrete Horde_Kolab_Server_Composite instance.
+     *
+     * @return Horde_Kolab_Server_Composite The newly created concrete
+     *                                      Horde_Kolab_Server_Composite
+     *                                      instance.
+     */
+    public function getComposite()
+    {
+        return $this->_factory->getComposite();
+    }
+
+    /**
+     * Return the object handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Objects The handler for objects on the server.
+     */
+    public function getObjects()
+    {
+        return $this->_factory->getObjects();
+    }
+
+    /**
+     * Return the structural representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Structure The representation of the db
+     *                                      structure.
+     */
+    public function getStructure()
+    {
+        return $this->_factory->getStructure();
+    }
+
+    /**
+     * Return the search handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Search The search handler.
+     */
+    public function getSearch()
+    {
+        return $this->_factory->getSearch();
+    }
+
+    /**
+     * Return the db schema representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Schema The db schema representation.
+     */
+    public function getSchema()
+    {
+        return $this->_factory->getSchema();
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Mapped.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Mapped.php
new file mode 100644 (file)
index 0000000..4424405
--- /dev/null
@@ -0,0 +1,154 @@
+<?php
+/**
+ * A factory decorator that adds mapping to the generated instances.
+ *
+ * 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
+ */
+
+/**
+ * A factory decorator that adds mapping to the generated instances.
+ *
+ * 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_Factory_Mapped
+implements Horde_Kolab_Server_Factory
+{
+    /**
+     * The factory used for creating the instances.
+     *
+     * @var Horde_Kolab_Server_Factory
+     */
+    private $_factory;
+
+    /**
+     * The attribute mapping.
+     *
+     * @var array
+     */
+    private $_mapping;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Kolab_Server_Factory $factory The base factory.
+     * @param array                      $mapping The attribute mapping.
+     */
+    public function __construct(
+        Horde_Kolab_Server_Factory $factory,
+        array $mapping)
+    {
+        $this->_factory = $factory;
+        $this->_mapping = $mapping;
+    }
+
+    /**
+     * Returns the conn factory.
+     *
+     * @return Horde_Kolab_Server_Factory_Conn The connection factory.
+     */
+    public function getConnectionFactory()
+    {
+        return $this->_factory->getConnectionFactory();
+    }
+
+    /**
+     * Returns the server configuration parameters.
+     *
+     * @return array The configuration parameters.
+     */
+    public function getConfiguration()
+    {
+        return $this->_factory->getConfiguration();
+    }
+
+    /**
+     * Return the server connection that should be used.
+     *
+     * @return Horde_Kolab_Server The Horde_Kolab_Server connection.
+     */
+    public function getServer()
+    {
+        $server = $this->_factory->getServer();
+        $server = new Horde_Kolab_Server_Mapped($server, $this->_mapping);
+        return $server;
+    }
+
+    /**
+     * Return the server that should be used.
+     *
+     * @return Horde_Kolab_Server_Connection The connection.
+     */
+    public function getConnection()
+    {
+        return $this->_factory->getConnection();
+    }
+
+    /**
+     * Returns a concrete Horde_Kolab_Server_Composite instance.
+     *
+     * @return Horde_Kolab_Server_Composite The newly created concrete
+     *                                      Horde_Kolab_Server_Composite
+     *                                      instance.
+     */
+    public function getComposite()
+    {
+        return $this->_factory->getComposite();
+    }
+
+    /**
+     * Return the object handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Objects The handler for objects on the server.
+     */
+    public function getObjects()
+    {
+        return $this->_factory->getObjects();
+    }
+
+    /**
+     * Return the structural representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Structure The representation of the db
+     *                                      structure.
+     */
+    public function getStructure()
+    {
+        return $this->_factory->getStructure();
+    }
+
+    /**
+     * Return the search handler that should be used.
+     *
+     * @return Horde_Kolab_Server_Search The search handler.
+     */
+    public function getSearch()
+    {
+        return $this->_factory->getSearch();
+    }
+
+    /**
+     * Return the db schema representation that should be used.
+     *
+     * @return Horde_Kolab_Server_Schema The db schema representation.
+     */
+    public function getSchema()
+    {
+        return $this->_factory->getSchema();
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/KolabTest.php b/framework/Kolab_Server/test/Horde/Kolab/Server/Class/Server/Factory/KolabTest.php
new file mode 100644 (file)
index 0000000..2b8a4e8
--- /dev/null
@@ -0,0 +1,182 @@
+<?php
+/**
+ * Test the default Kolab server factory.
+ *
+ * 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
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../../Autoload.php';
+
+/**
+ * Test the default Kolab server factory.
+ *
+ * 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
+ */
+class Horde_Kolab_Server_Class_Server_Factory_KolabTest
+extends PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->conn_factory = $this->getMock('Horde_Kolab_Server_Factory_Conn');
+        $this->connection = $this->getMock('Horde_Kolab_Server_Connection');
+    }
+
+    public function testMethodConstructHasParametersConnectionfactoryAndArrayParameters()
+    {
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array()
+        );
+    }
+
+    public function testMethodGetconnectionfactoryHasResultTheStoredConnectionfactory()
+    {
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array()
+        );
+        $this->assertSame($this->conn_factory, $factory->getConnectionFactory());
+    }
+
+    public function testMethodGetconfigurationHasResultTheStoredConfigurationParameters()
+    {
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array('a' => 'a')
+        );
+        $this->assertEquals(array('a' => 'a'), $factory->getConfiguration());
+    }
+
+    public function testMethodGetconnectionHasResultConnection()
+    {
+        $this->conn_factory->expects($this->once())
+            ->method('setConfiguration')
+            ->with(array());
+        $this->conn_factory->expects($this->once())
+            ->method('getConnection')
+            ->will($this->returnValue($this->connection));
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array()
+        );
+        $this->assertType(
+            'Horde_Kolab_Server_Connection',
+            $factory->getConnection()
+        );
+    }
+
+    public function testMethodGetobjectsHasResultObjectsbase()
+    {
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array()
+        );
+        $this->assertType(
+            'Horde_Kolab_Server_Objects_Base',
+            $factory->getObjects()
+        );
+    }
+
+    public function testMethodGetsearchHasResultSearchbase()
+    {
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array()
+        );
+        $this->assertType(
+            'Horde_Kolab_Server_Search_Base',
+            $factory->getSearch()
+        );
+    }
+
+    public function testMethodGetsearchHasResultSchemabase()
+    {
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array()
+        );
+        $this->assertType(
+            'Horde_Kolab_Server_Schema_Base',
+            $factory->getSchema()
+        );
+    }
+
+    public function testMethodGetstructureHasResultStructurekolab()
+    {
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array()
+        );
+        $this->assertType(
+            'Horde_Kolab_Server_Structure_Kolab',
+            $factory->getStructure()
+        );
+    }
+
+    public function testMethodGetserverHasResultServerldapstandard()
+    {
+        $this->conn_factory->expects($this->once())
+            ->method('getConnection')
+            ->will($this->returnValue($this->connection));
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array('basedn' => 'test')
+        );
+        $this->assertType(
+            'Horde_Kolab_Server_Ldap_Standard',
+            $factory->getServer()
+        );
+    }
+
+    public function testMethodGetserverHasResultServerldapfilteredIfTheFilterOptionIsSet()
+    {
+        $this->conn_factory->expects($this->once())
+            ->method('getConnection')
+            ->will($this->returnValue($this->connection));
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array('basedn' => 'test', 'filter' => 'a')
+        );
+        $this->assertType(
+            'Horde_Kolab_Server_Ldap_Filtered',
+            $factory->getServer()
+        );
+    }
+
+    public function testMethodGetserverThrowsExceptionIfTheBasednIsMissingInTheConfiguration()
+    {
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array()
+        );
+        try {
+            $factory->getServer();
+            $this->fail('No exception!');
+        } catch (Horde_Kolab_Server_Exception $e) {
+            $this->assertEquals('The base DN is missing', $e->getMessage());
+        }
+    }
+
+    public function testMethodGetcompositeHasResultComposite()
+    {
+        $this->conn_factory->expects($this->once())
+            ->method('getConnection')
+            ->will($this->returnValue($this->connection));
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $this->conn_factory, array('basedn' => 'test')
+        );
+        $this->assertType(
+            'Horde_Kolab_Server_Composite',
+            $factory->getComposite()
+        );
+    }
+
+
+}
\ No newline at end of file