Configuration based factories should not require any parameters but the configuration.
authorGunnar Wrobel <p@rdus.de>
Wed, 28 Oct 2009 21:38:37 +0000 (22:38 +0100)
committerGunnar Wrobel <p@rdus.de>
Wed, 28 Oct 2009 21:41:16 +0000 (22:41 +0100)
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Configuration.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Configuration.php [new file with mode: 0644]
framework/Kolab_Server/package.xml

index c54ca48..b031dd9 100644 (file)
@@ -44,15 +44,18 @@ implements Horde_Kolab_Server_Factory
 
     /**
      * Constructor.
-     *
-     * @param array $config Configuration parameters for the server.
      */
-    public function __construct(
-        Horde_Kolab_Server_Factory $factory,
-        array $config
-    ) {
+    public function __construct(array $config)
+    {
         $this->_configuration = $config;
 
+        $connection_factory = new Horde_Kolab_Server_Factory_Conn_Configuration(
+            $config
+        );
+        $factory = new Horde_Kolab_Server_Factory_Kolab(
+            $connection_factory, $config
+        );
+
         if (isset($config['logger'])) {
             $factory = new Horde_Kolab_Server_Factory_Logged(
                 $factory, $config['logger']
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Configuration.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Factory/Conn/Configuration.php
new file mode 100644 (file)
index 0000000..6f4dba1
--- /dev/null
@@ -0,0 +1,92 @@
+<?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 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_Configuration
+extends Horde_Kolab_Server_Factory_Conn_Base
+{
+    /**
+     * Configuration parameters for the connection.
+     *
+     * @var array
+     */
+    private $_configuration;
+
+    /**
+     * The factory used for creating the instances.
+     *
+     * @var Horde_Kolab_Server_Factory
+     */
+    private $_factory;
+
+    /**
+     * Constructor.
+     */
+    public function __construct(array $config)
+    {
+        $this->setConfiguration($config);
+    }
+
+    /**
+     * Get the connection configuration.
+     *
+     * @return array $configuration The configuration parameters.
+     */
+    public function getConfiguration()
+    {
+        return $this->_configuration;
+    }
+
+    /**
+     * Set the connection configuration.
+     *
+     * @param array $configuration The configuration parameters.
+     *
+     * @return NULL
+     */
+    public function setConfiguration(array $configuration)
+    {
+        $this->_configuration = $configuration;
+
+        if (empty($configuration['mock'])) {
+            $this->_factory = new Horde_Kolab_Server_Factory_Conn_Ldap();
+        } else {
+            $this->_factory = new Horde_Kolab_Server_Factory_Conn_Mock();
+        }
+
+        $this->_factory->setConfiguration($configuration);
+    }
+
+    /**
+     * Return the server connection that should be used.
+     *
+     * @return Horde_Kolab_Server_Connection The server connection.
+     */
+    public function getConnection()
+    {
+        return $this->_factory->getConnection();
+    }
+}
\ No newline at end of file
index efafca5..0891eea 100644 (file)
@@ -85,6 +85,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
         <file name="Conn.php" role="php" />
         <dir name="Conn">
          <file name="Base.php" role="php" />
+         <file name="Configuration.php" role="php" />
          <file name="Injector.php" role="php" />
          <file name="Ldap.php" role="php" />
          <file name="Mock.php" role="php" />
@@ -320,6 +321,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Kolab/Server/Factory/Configuration.php" as="Horde/Kolab/Server/Factory/Configuration.php" />
    <install name="lib/Horde/Kolab/Server/Factory/Conn.php" as="Horde/Kolab/Server/Factory/Conn.php" />
    <install name="lib/Horde/Kolab/Server/Factory/Conn/Base.php" as="Horde/Kolab/Server/Factory/Conn/Base.php" />
+   <install name="lib/Horde/Kolab/Server/Factory/Conn/Configuration.php" as="Horde/Kolab/Server/Factory/Conn/Configuration.php" />
    <install name="lib/Horde/Kolab/Server/Factory/Conn/Injector.php" as="Horde/Kolab/Server/Factory/Conn/Injector.php" />
    <install name="lib/Horde/Kolab/Server/Factory/Conn/Ldap.php" as="Horde/Kolab/Server/Factory/Conn/Ldap.php" />
    <install name="lib/Horde/Kolab/Server/Factory/Conn/Mock.php" as="Horde/Kolab/Server/Factory/Conn/Mock.php" />